Re: Date formatting
Re: Date formatting
- Subject: Re: Date formatting
- From: Nigel Smith <email@hidden>
- Date: Tue, 04 Mar 2003 11:27:12 +0000
On 4/3/03 5:18, "Marc K. Myers" <email@hidden> wrote:
>
Is there a way to use Unix utilities in an AppleScript to format dates
>
from a date variable to text using the kind of formatting capabilities
>
that are in the "date" command? How would it work?
How's about this for starters?
----------------
--get time 0 for the Unix side
set theEpoch to (date "Thursday, January 1, 1970 0:00:00")
--current time in seconds from time 0, as text (for next bit)
set theDiff to ((current date) - theEpoch) as text
--convert the any scientific notation to an "integer" string
if theDiff contains "E" then
set thePower to (last character of theDiff) + 1
set theDiff to (first character of theDiff & <line-break>
(characters 3 thru -4 of theDiff as text))
repeat until (length of theDiff) = thePower
set theDiff to theDiff & "0"
end repeat
end if
--do the shell script
return (do shell script ("date -r " & theDiff & <line-break>
" +\"DATE: %m/%d/%y%nTIME: %H:%M:%S\""))
----------------
Bit of a kludge on the real-to-integer conversion, works well enough but I'm
sure someone can do better.
Nigel
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.