0

There is a list of date format codes: https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes

Is there a way to get a list of supported format codes for your platform? I can't find where format codes are located in source code.

Is there a way to do something like?

import datetime
datetime.get_supported_format_codes()
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Andrius
  • 19,658
  • 37
  • 143
  • 243

1 Answers1

1

According to the documentation concerning the date format codes:

The following is a list of all the format codes that the 1989 C standard requires, and these work on all platforms with a standard C implementation.

However, some ISO 8601 date values are included, but they're not available on all platforms when used with the strftime() method.

If you're going to call an ambiguous or incomplete ISO 8601 parameter, you're going to get a ValueError

So, if you want to get the full set of format codes, you'd have to consult the strftime() documentation, as supported values for the codes vary across platform, because Python calls the platform C library's strftime(3) function.

For Linux see this page. For Mac check this url.

As for the code, I'm not aware of any method that does what you want.

Source code for datetime.py is here.

baduker
  • 19,152
  • 9
  • 33
  • 56