Re: Specific Date-Time Formatting
Re: Specific Date-Time Formatting
- Subject: Re: Specific Date-Time Formatting
- From: "Mark J. Reed" <email@hidden>
- Date: Thu, 3 Nov 2005 20:52:26 -0500
On 11/3/05, Chris Tangora <email@hidden> wrote:
Hi All, I found this in the archive and wanted to know if there
was an option to get the date from two days in the future. I'm
trying to make script that will look ahead for what the month and day
will be in numerical format. I'm using the shell script "date" to
get the current date, but I want to get that same info as + 2 days.
If you can get what you want out of the AppleScript date class as
posted by others, that's your best bet. If you find you something
fancier that's helped by the formatting capabilities of the date
command, you do have some options.
1. If you can calculate the time value as seconds from Jan 1, 1970, you can pass it to date via the -r option:
date -r 1000000000 +%Y-%m-%d --> 2001-09-08
The problem is getting that value; the AS date class doesn't coerce to
a number. You can subtract whatever time 0 works out to in your
local time zone and format settings - for me, that's (date "1969-12-31
19:00:00") - but the result is such a large number that AS stringifies
it using scientific notation (e.g. 1.131050241E+9 instead of just
1131050241) which the date command doesn't understand.
2. You could use something like Perl, which provides an interface to
the same strftime() function that underlies the date command's
formatting capabilities;
do shell script "perl -MPOSIX=strftime -le 'print strftime(\"%Y-%m-%d
%H:%M:%S\", localtime(time + 2 * 24 * 60 * 60))' " --> 2005-11-05
20:51:17
Perl, sadly, lacks the convenient constants like days, minutes, and hours, but you can always have AS supply them for you:
do shell script "perl -MPOSIX=strftime -le 'print strftime(\"%Y-%m-%d
%H:%M:%S\", localtime(time + 2 * " & days & "))' " -->
2005-11-05
20:51:29
3. If you're feeling bold, you could install the GNU version of the
date command, which lets you specify the date in a human-friendly form
using the -d option:
do shell script "/usr/local/bin/gdate -d 'now + 2 days' +'%m %d' " --> 11 05
--
Mark J. Reed <
email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden