Python time formatting different in Windows

后端 未结 3 720
感动是毒
感动是毒 2020-12-05 18:43

I\'m probably missing an obvious platform difference that I should be accommodating but I\'m getting this when trying to do a time format (Python2.7)...

in Linux env

相关标签:
3条回答
  • 2020-12-05 19:22

    In general, you'll find that python time.strftime() supports the same set of format specifiers as the platform (or that platform's libc to be more specific) it runs on. However, only a subset of these is portable. See http://docs.python.org/library/time.html for a list. To quote the docs:

    Additional directives may be supported on certain platforms, but only the ones listed here have a meaning standardized by ANSI C.

    In this case, %T can be replaced by %H:%M:%S.

    0 讨论(0)
  • 2020-12-05 19:23

    I found that I had this problem because MacOS supports "%D" and I had to replace it with "%m/%d/%Y" to make it cross-platform. In general, combining 'simple' format strings like %m seems to be safer than using 'aggregate' strings like %T or %D.

    0 讨论(0)
  • 2020-12-05 19:30

    I don't see the %T format directive listed in the Python documentation - must not be available/implemented for the Windows platform (I tried with both Python v2.7.3 and 3.2.3 just now)

    0 讨论(0)
提交回复
热议问题