Cover by Jay A. Kreibich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

Name

strftime() — Decode time string into any format

Common Usage

strftime( format, timestring, modifier1, modifier2, ... )

Description

The strftime() function returns a formatted string by taking a timestring (with modifiers) and formating it according to format , a printf() style format specification. If any of the parameters are in an incorrect or illegal format, a NULL is returned.

The format string can contain any of the following markers:

  • %d — day of the month ( DD ), 01-31

  • %f — seconds with fractional part (SS.sss), 00-59 plus decimal portion

  • %H — hour ( HH ), 00-23

  • %j — day of the year ( NNN ), 001-366

  • %J — Julian Day number (DDDDDDD.ddddddd)

  • %m — month ( MM ), 01-12

  • %M — minute ( MM ), 00-59

  • %s — seconds since 1970-01-01 (Unix epoch)

  • %S — seconds ( SS ), 00-59

  • %w — day of the week ( N ), starting with Sunday as 0

  • %W — week of the year ( WW ), 00-53

  • %Y — year ( YYYY )

  • %% — a literal %

The timestring value can be in any of these formats:

  • YYYY-MM-DD

  • YYYY-MM-DD HH:MM

  • YYYY-MM-DD HH:MM:SS

  • YYYY-MM-DD HH:MM:SS.sss

  • YYYY-MM-DDTHH:MM

  • YYYY-MM-DDTHH:MM:SS

  • YYYY-MM-DDTHH:MM:SS.sss

  • HH:MM

  • HH:MM:SS

  • HH:MM:SS.sss

  • now

  • DDDDDDD

  • DDDDDDD.ddddddd

All hour values use a 24-hour clock. Any value that is not given will be implied. Any implied hour, minute, second, or subsecond is zero. Any implied month or day of month is 1. Any implied year is 2000. The full date and time formats allow either a space or a literal uppercase T between the date and time. The last two values (a single, large integer ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required