Search code examples
python-3.xpython-datetime

datetime strptime(), how to get format table


In the docs of the strftime() and strptime() behavior laid out list of format codes. How does datetime store it? Can i get access to it?

I mean, when i use strptime(date_string, format), its somehow handle 'format' string, so, it has to know how to associate, say, '%d' to a range of integers '01, 02, …, 31' as it described in docs. So, how does it store those associations and can i get access to them?


Solution

  • From the documentation:

    The full set of format codes supported varies across platforms, because Python calls the platform C library’s strftime() function, and platform variations are common. To see the full set of format codes supported on your platform, consult the strftime(3) documentation.

    On Linux and macOS, you can run man strftime to see the supported format codes.

    The documentation includes a table of standard format codes:

    The following is a list of all the format codes that the C standard (1989 version) requires, and these work on all platforms with a standard C implementation. Note that the 1999 version of the C standard added additional format codes.

    Update

    In response to your comment below, the format codes are part of the C library for the platform. I know of no way to access them from Python.