Transforms a YYYYMMDDHH24MISS timestamp into the specified date/time format.
FormatTime, OutputVar , YYYYMMDDHH24MISS, Format
The name of the output variable in which to store the result.
Leave this parameter blank to use the current local date and time. Otherwise, specify all or the leading part of a timestamp in the YYYYMMDDHH24MISS format. If the date and/or time portion of the timestamp is invalid -- such as February 29th of a non-leap year -- the date and/or time will be omitted from OutputVar. Although only years between 1601 and 9999 are supported, a formatted time can still be produced for earlier years as long as the time portion is valid.
If omitted, it defaults to the time followed by the long date, both of which will be formatted according to the current user's locale. Por exemplo: 4:55 PM Saturday, November 27, 2004
Otherwise, specify one or more of the date-time formats below, along with any literal spaces and punctuation in between (commas do not need to be escaped; they can be used normally). In the following example, note that M must be capitalized: M/d/yyyy h:mm tt
The following formats must be used alone; that is, with no other formats or text present in the Format parameter. These formats are not case sensitive.
The following options can appear inside the YYYYMMDDHH24MISS parameter immediately after the timestamp (if there is no timestamp, they may be used alone). In the following example, note the lack of commas between the last four items:
FormatTime, OutputVar, 20040228 LSys D1 D4
R: Reverse. Have the date come before the time (meaningful only when Format is blank).
Ln: If this option is not present, the current user's locale is used to format the string. To use the system's locale instead, specify LSys. To use a specific locale, specify the letter L followed by a hexadecimal or decimal locale identifier (LCID). For information on how to construct an LCID, search www.microsoft.com for the following phrase: Locale Identifiers
Dn: Date options. Specify for n one of the following numbers:
Tn: Time options. Specify for n one of the following numbers:
Observação: Dn and Tn may be repeated to put more than one option into effect, such as this example: FormatTime, OutputVar, 20040228 D2 D4 T1 T8
FormatTime, OutputVar, 20040228 D2 D4 T1 T8
Letters and numbers that you want to be transcribed literally from Format into OutputVar should be enclosed in single quotes as in this example: 'Date:' MM/dd/yy 'Time:' hh:mm:ss tt.
'Date:' MM/dd/yy 'Time:' hh:mm:ss tt
By contrast, non-alphanumeric characters such as spaces, tabs, linefeeds (`n), slashes, colons, commas, and other punctuation do not need to be enclosed in single quotes. The exception to this is the single quote character itself: to produce it literally, use four consecutive single quotes (''''), or just two if the quote is already inside an outer pair of quotes.
If Format contains date and time elements together, they must not be intermixed. In other words, the string should be dividable into two halves: a time half and a date half. For example, a format string consisting of "hh yyyy mm" would not produce the expected result because it has a date element in between two time elements.
When Format contains a numeric day of the month (either d or dd) followed by the full month name (MMMM), the genitive form of the month name is used (if the language has a genitive form).
If Format contains more than 2000 characters, OutputVar will be made blank.
On a related note, addition and subtraction of dates and times can be performed with EnvAdd and EnvSub.
To convert in the reverse direction -- that is, from a formatted date/time to YYYYMMDDHH24MISS format -- see www.autohotkey.com/forum/topic20405.html
Veja também: Gui DateTime control, Format(), SetFormat, Transform, built-in date and time variables, FileGetTime
Demonstrates different usages.
FormatTime, TimeString MsgBox The current time and date (time first) is %TimeString%. FormatTime, TimeString, R MsgBox The current time and date (date first) is %TimeString%. FormatTime, TimeString,, Time MsgBox The current time is %TimeString%. FormatTime, TimeString, T12, Time MsgBox The current 24-hour time is %TimeString%. FormatTime, TimeString,, LongDate MsgBox The current date (long format) is %TimeString%. FormatTime, TimeString, 20050423220133, dddd MMMM d, yyyy hh:mm:ss tt MsgBox The specified date and time, when formatted, is %TimeString%. FormatTime, TimeString, 200504, 'Month Name': MMMM`n'Day Name': dddd MsgBox %TimeString% FormatTime, YearWeek, 20050101, YWeek MsgBox January 1st of 2005 is in the following ISO year and week number: %YearWeek%
Changes the date-time stamp of a file.
FileSelectFile, FileName, 3,, Pick a file if (FileName = "") ; The user didn't pick a file. return FileGetTime, FileTime, %FileName% FormatTime, FileTime, %FileTime% ; Since the last parameter is omitted, the long date and time are retrieved. MsgBox The selected file was last modified at %FileTime%.
Converts the specified number of seconds into the corresponding number of hours, minutes, and seconds (hh:mm:ss format).
MsgBox % FormatSeconds(7384) ; 7384 = 2 hours + 3 minutes + 4 seconds. It yields: 2:03:04 FormatSeconds(NumberOfSeconds) ; Convert the specified number of seconds to hh:mm:ss format. { time := 19990101 ; *Midnight* of an arbitrary date. time += NumberOfSeconds, seconds FormatTime, mmss, %time%, mm:ss return NumberOfSeconds//3600 ":" mmss /* ; Unlike the method used above, this would not support more than 24 hours worth of seconds: FormatTime, hmmss, %time%, h:mm:ss return hmmss */ }