Re: [OT] Shell scripting
Re: [OT] Shell scripting
- Subject: Re: [OT] Shell scripting
- From: "Marc K. Myers" <email@hidden>
- Date: Sat, 27 Dec 2003 20:05:44 -0500
From: Reinhold Penner <email@hidden>
Subject: Re: [OT] Shell scripting
Date: Fri, 26 Dec 2003 15:22:14 -1000
To: email@hidden
I was wondering if there is a shell way to apply the formatting to an
arbitrary date string. For example get the creation/modification date
of a file and format that as easily as below.
-Reinhold
On Dec 26, 2003, at 6:51, John W. Baxter wrote:
Change the echo command to something along these lines (watch line
wrapping):
echo "AppleFileServer restarted by autoAfpCheck at `date +%H:%M\ on\
%Y-%m-%d`"
Which gives
AppleFileServer restarted by autoAfpCheck at 08:46 on 2003-12-26
man strftime
will reveal the various codes you could use instead of what I used.
This should do what you want:
set theEpoch to date (do shell script "date -r 0 +'%m/%d/%Y %H:%M:%S'")
set arbitraryDate to date "Thursday, January 22, 1987 3:23:24 AM"
--get time in seconds since the Unix epoch
set theDiff to (arbitraryDate - theEpoch) as text
--convert 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 & (characters 3 thru -4
of theDiff as text))
repeat until (length of theDiff) = thePower
set theDiff to theDiff & "0"
end repeat
end if
set formattedDate to (do shell script "date -r " & theDiff & "
+'%m/%d/%Y %H:%M:%S'")
--> "01/22/1987 03:23:24"
The symbols used to format dates are listed in the strftime manual.
(man strftime)
Marc [12/27/03 8:05:41 PM]
_______________________________________________
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.