Skip to content

dateTimeToStr

MicroBlaster edited this page Mar 12, 2023 · 2 revisions

Purpose: Converts a Unix/Julian Datetime to string with an optional format.

Syntax: getDate var DateTime

var: A variable that will contain the result. DateTime: A Unix/Julian Datetime to be converted. Format: Optional Format:

Notes: This command will return the date in the current system format. Note that this date will vary depending upon your regional settings.

The optional format string will specify the appearance of the result.

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.

Example:

dateTimeToStr $var $now "'The time is -' h:mm:ss, ' the date is -' m/dd/yyyy'"
echo $var "*"
dateTimeToStr $var $now "'             h:m:s = ' h:m:s"
echo $var "*"
dateTimeToStr $var $now "'          hh:mm:ss = ' hh:mm:ss"
echo $var "*"
dateTimeToStr $var $now "' dd/mm/yy hh:mm:ss = ' dd/mm/yy hh:mm:ss"
echo $var "*"
dateTimeToStr $var $now "'dddd mmmm dd, yyyy = ' dddd mmmm dd, yyyy"
echo $var "*"

#Outputs:

The time is - 8:07:02,  the date is - 7/05/2022
             h:m:s =  8:7:2
          hh:mm:ss =  08:07:02
 dd/mm/yy hh:mm:ss =  05/07/22 08:07:02
dddd mmmm dd, yyyy =  Tuesday July 05, 2022



Clone this wiki locally