In yesterday’s entry, System Time/Date Script, I showed how to use the built-in Time function to display the current (system) time and date.
To change format, the strftime method has a number of options available.
Its basic format is
where format is the format string to be used, which may be specified with the following:
- %A – Full day of the week (Sunday, Monday, etc.)
- %a – Abbreviated day of the week (Sun, Mon, etc.)
- %B – Full month (January, February, etc.)
- %b – Abbreviated month (Jan, Feb, etc.)
- %c – Current Date and Time (system clock format)
- %d – Day of the month (01-31)
- %H – Time of day in 24-hour format (00-23)
- %I – Time of day in 12-hour format (01-12)
- %j – Day of the year (001-366)
- %M – Minutes (00-59)
- %m Numerical month of the year (01-12)
- %p – Displays AM or PM after the time
- %S – The number of seconds (00-60, 60 being a “leap second”)
- %U – Week of the year, the first week starting with the first Sunday (00-53)
- %W – Week of the year, the first week starting with the first Monday (00-53)
- %w – Day of the week (0-6, 0 denoting Sunday)
- %X – Displays the Time
- %x – Displays the Date
- %Y – Displays the Year as a 4-digit number (2009)
- %y – Displays the Year as a 2-digit number (00-99)
- %Z – Displays the default (system) Time Zone
- %% – Displays a % character
Note that this is case sensitive.
So, as an example, to display the full date, including day, month and year, strftime would be set to:
The result would be
And that’s it!