getTime
MicroBlaster edited this page Nov 10, 2019
·
2 revisions
Purpose: Retrieves the current system time, or a formatted value containing the time and/or date.
Syntax: getTime var [{format}]
var: A variable to hold the formatted time or date.
[{format}]: The format in which to return the time/date. If this is not specified, the variable will be set to hold the current system time in its default format.
Notes: This is an extemely powerful date/time formatting command.
Some components of the 'format' command are:
"d" : Displays the day of the month without a leading zero.
"dd" : Displays the day of the month with a leading zero.
"m": Displays the month without a leading zero.
"mm": Displays the month with a leading zero.
"yy": Displays a two digit year.
"yyyy": Displays a four digit year.
"h": Displays the hour without a leading zero.
"hh": Displays the hour with a leading zero.
"n": Displays the minute without a leading zero.
"nn": Displays the minute with a leading zero.
"s": Displays the second without a leading zero.
"ss": Displays the second with a leading zero.
"am/pm": Displays "am" or "pm" depending upon the time.
"a/p": Displays "a" or "p" depending upon the time.
"c": Displays the date in its system date format.
"t": Displays the time in its system time format.
Any characters within quotes are left as they are (without formatting). Unidentified components are simply shown as-is.
Example:
getTime $test "'The time is :' h:m:s, ' the date is :' d:m:yyyy'"
# displays: The time is : 12:22:28, the date is : 11:4:2003
echo $test
.