Re: padding dates etc.
Re: padding dates etc.
- Subject: Re: padding dates etc.
- From: Jim Underwood <email@hidden>
- Date: Tue, 13 Mar 2018 06:10:21 +0000
- Thread-topic: padding dates etc.
JC, I'm sure you'll get lots of answers.
Here's how I'd do it, probably using the shell script method:
________________________________
set dateISOStr to ((current date) as «class isot») as string
set AppleScript's text item delimiters to {"-", "T", ":"}
set dateParts to text items of dateISOStr
set AppleScript's text item delimiters to ""
set verNumStr1 to dateParts as text
-->20180313010728
-- OR --
set verNumStr2 to do shell script "date '+%Y%m%d%s'"
-->201803131520921248
________________________________
Best Regards,
Jim Underwood
aka JMichaelTX
From: AppleScript-Users
<applescript-users-bounces+jmichael=email@hidden<mailto:applescript-users-bounces+jmichael=email@hidden>>
on behalf of Jean-Christophe Helary
<email@hidden<mailto:email@hidden>>
Date: Tuesday, March 13, 2018 at 12:49 AM
To: "ASUL (AppleScript)"
<email@hidden<mailto:email@hidden>>
Subject: padding dates etc.
I'm trying to get a yyymmddsssss string to use as a version number and I use
the following code:
set omegat_versionto ¬
((yearof (omegat_creation_date) as string) & ¬
(JC'smyPadding:2 myNumber:(monthof (omegat_creation_date) as integer)) & ¬
(JC'smyPadding:2 myNumber:(dayof (omegat_creation_date) as integer)) & ¬
(JC'smyPadding:5 myNumber:(timeof (omegat_creation_date) as integer))) ¬
as integer
where the padding routine is:
on myPadding:myPaddingmyNumber:myNumber
# adds enough 0 to the left of the number to pad it to the myPadding value
# if the number is already long enough, less significant numbers on the right
are removed until the correct length is achieved
set myLength to (numberof itemsof (myNumber as text))
ifmyLength < myPaddingthen
set myEndNumber to (text 2 thru -1 of ((10 ^ (myPadding - myLength) as integer)
as text)) & (myNumberas text)
else if myLength = myPadding then
setmyEndNumber to myNumber
else if myLength > myPadding then
set myEndNumber to (text 1 thru myPadding of (myNumber as text))
end if
returnmyEndNumber
end myPadding:myNumber:
and I'm wondering if there is a less convoluted way to accomplish the same
result...
:-)
Jean-Christophe Helary
-----------------------------------------------
http://mac4translators.blogspot.com @brandelune
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden