Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python3 strftime output varies by platform

Python3 strftime produces results that vary by platform. For example:

OS X 10.10.5

>>> sys.version
'3.5.2 (v3.5.2:4def2a2901a5, Jun 26 2016, 10:47:25) \n[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]'
>>> datetime.datetime(1, 1, 1, 0, 0).strftime('%Y/%m/%d')
'0001/01/01'

Debian 8.5

>>> sys.version
'3.5.2 (default, Aug 12 2016, 16:05:15) \n[GCC 4.9.2]'
>>> datetime.datetime(1, 1, 1, 0, 0).strftime('%Y/%m/%d')
'1/01/01'

Is this expected behavior? Why?

like image 772
kkurian Avatar asked Dec 05 '25 18:12

kkurian


1 Answers

strftime is just a thin-wrapper around the strftime function defined in the C library you're using. See a related 'bug' here. This behavior seems to be another case of exactly that.

Differences between the output don't relate to Python since Python will just pass in the arguments and receives the output. Since different platforms have different implementations of the C stdlib, you'll get differing results in some edge cases.

like image 134
Dimitris Fasarakis Hilliard Avatar answered Dec 08 '25 20:12

Dimitris Fasarakis Hilliard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!