Re: Date Help - D&T stamp w Short dates
Re: Date Help - D&T stamp w Short dates
- Subject: Re: Date Help - D&T stamp w Short dates
- From: "Arthur J. Knapp" <email@hidden>
- Date: Mon, 06 Jan 2003 13:45:37 -0500
>
Date: Mon, 06 Jan 2003 09:40:21 -0800
>
Subject: Date Help - D&T stamp w Short dates
>
From: "Domains4Days.com" <email@hidden>
>
Basically, I would like to create a date - time stamp that ideally would
>
look like the following
>
IDEAL1: 01-06-03 09-23-21 AM (mm-dd-yy)
>
IDEAL2: 2003-01-06 09-23-21 AM (yyyy-mm-dd)
I keep forgetting to optimize this handler:
set ideal1 to DateToString( "mm-dd-yy hh-MM-ss ?m", current date )
set ideal2 to DateToString( "yyyy-mm-dd hh-MM-ss ?m", current date )
on DateToString(sFormat, _d_)
(*
* yyyy 4 digit year
* yy 2 digit year
* mmmm full month name
* mmm 3 letter month name
* mm month, padded
* m month
* dddd full day name
* ddd 3 letter day name
* dd date, padded
* d date
* hh hour, padded
* h hour
* HH hour, 24, padded
* H hour, 24
* MM minutes, padded
* M minutes
* ss seconds, padded
* s seconds
* ?m am/pm
* ` escape character
* ~ null character
*)
if (_d_'s class = date) then
set d to _d_
else
set d to current date
end if
if (sFormat's class is not string) or
(sFormat's length = 0) then return d as string --> default
set s to sFormat & " " --> prevent out-of-bounds in parsing
set t to ""
considering case
repeat until s's length < 5
if (s starts with "yy") then
set v to d's year as string
if (s starts with "yyyy") then
set t to t & v
set s to s's text 5 thru -1
else
set t to t & v's text -2 thru -1
set s to s's text 3 thru -1
end if
else if (s starts with "m") then
if (s starts with "mmm") then
set v to d's month as string
if (s starts with "mmmm") then
set t to t & v
set s to s's text 5 thru -1
else
set t to t & v's text 1 thru 3
set s to s's text 4 thru -1
end if
else
-- French Vanilla method, via Emmanual Levy
copy d to b
set b's month to January
set v to 1 + (d - b + 1314864) div 2629728
if (s starts with "mm") then
set t to t & ("0" & v)'s text -2 thru -1
set s to s's text 3 thru -1
else
set t to t & v
set s to s's text 2 thru -1
end if
end if
else if (s starts with "d") then
if (s starts with "ddd") then
set v to d's weekday as string
if (s starts with "dddd") then
set t to t & v
set s to s's text 5 thru -1
else
set t to t & v's text 1 thru 3
set s to s's text 4 thru -1
end if
else
set v to d's day as string
if (s starts with "dd") then
set t to t & ("0" & v)'s text -2 thru -1
set s to s's text 3 thru -1
else
set t to t & v
set s to s's text 2 thru -1
end if
end if
else if (s starts with "h") or (s starts with "H") then
set v to (d's time) div 60 div 60
if (s starts with "h") and (v > 12) then
set v to v - 12
ignoring case
if (s starts with "hh") then
set t to t & ("0" & v)'s text -2 thru -1
set s to s's text 3 thru -1
else
set t to t & v
set s to s's text 2 thru -1
end if
end ignoring
else if (s starts with "M") then
set v to (d's time) div 60 mod 60
if (s starts with "MM") then
set t to t & ("0" & v)'s text -2 thru -1
set s to s's text 3 thru -1
else
set t to t & v
set s to s's text 2 thru -1
end if
else if (s starts with "s") then
set v to (d's time) mod 60
if (s starts with "ss") then
set t to t & ("0" & v)'s text -2 thru -1
set s to s's text 3 thru -1
else
set t to t & v
set s to s's text 2 thru -1
end if
else if (s starts with "?m") then
if ((d's time) div 60 div 60 < 12) then
set t to t & "AM"
else
set t to t & "PM"
end if
set s to s's text 3 thru -1
else if (s starts with "`") then
set t to t & s's character 2
set s to s's text 3 thru -1
else if (s starts with "~") then
set s to s's text 2 thru -1
else
set t to t & s's character 1
set s to s's text 2 thru -1
end if
end repeat
end considering
return t
end DateToString
{ Arthur Knapp, of <
http://www.STELLARViSIONs.com>
a r t h u r @ s t e l l a r v i s i o n s . c o m
"Safe the Nature" - political graffiti in Prague
}
_______________________________________________
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.