How can I edit the format of the receivedDate.
Now it looks like " dinsdag, 13 december 2004 17:00:34"
How can i make this look like “17:00:34”, just the time or look like “13-12-04” ?
And another question:
I want to change a text. The text is always ending on “.txt”. How can I remove the “.txt” in that variable.
Thanks in advance
-- set variables for date
set receivedDate to current date
set Cday to the day of receivedDate
set Cmonth to the month of receivedDate
set Cyear to the year of receivedDate
if (Cmonth = January) then
set Cmonth to "01"
else if (Cmonth = February) then
set Cmonth to "02"
else if (Cmonth = March) then
set Cmonth to "03"
else if (Cmonth = April) then
set Cmonth to "04"
else if (Cmonth = May) then
set Cmonth to "05"
else if (Cmonth = June) then
set Cmonth to "06"
else if (Cmonth = July) then
set Cmonth to "07"
else if (Cmonth = August) then
set Cmonth to "08"
else if (Cmonth = September) then
set Cmonth to "09"
else if (Cmonth = October) then
set Cmonth to "10"
else if (Cmonth = November) then
set Cmonth to "11"
else if (Cmonth = December) then
set Cmonth to "12"
end if
-- set formatting variables
set FormattedDate to Cday & "-" & Cmonth & "-" & Cyear as string
display dialog FormattedDate
-- display time
set Ctime to the time string of receivedDate as string
display dialog Ctime
Do you perhaps also know how I can solve this problem? The text in a vaiable is always ending on “.txt”. How can I remove the “.txt” in that variable.
Thanks in advance
The simplest way to handle the time on your own computer would be:
set receivedTime to time string of receivedDate
The caveat here is that ‘time string’ formats the time according to the current user’s Date and Time preferences. So on someone else’s machine, the result might be “5:00:34 pm”. If you want to force a result in your own style, you could do something like this (assuming you use leading zeros on the hours too, when necessary):
set t to time of receivedDate
-- The following calculation conveniently provides any necessary leading zeros.
tell (1000000+ t div hours*10000 + t mod hours div minutes * 100 + t mod minutes) as string
set receivedTime to text 2 thru 3 & ":" & text 4 thru 5 & ":" & text 6 thru 7
end tell
I believe that a ‘short date string’ command was added from OS 10.3 onwards, which will return “13-12-04” if that’s the format set up in your own preferences. For earlier systems — or to force your own format — there’s this:
set {year:y, day:d} to receivedDate
-- This calculates the month number.
copy receivedDate to b
set b's month to January
set m to (b - 2500000 - receivedDate) div -2500000
-- The following calculation conveniently provides any necessary leading zeros.
tell (y * 10000 + m * 100 + d) as string
set shortDateReceived to text 7 thru 8 & "-" & text 5 thru 6 & "-" & text 3 thru 4
end tell