classification
Title: strftime is broken
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: jonathan.cervidae, r.david.murray
Priority: normal Keywords:

Created on 2009-05-11 17:58 by jonathan.cervidae, last changed 2009-05-11 22:52 by jonathan.cervidae. This issue is now closed.

Messages (3)
msg87582 - (view) Author: Jonathan (jonathan.cervidae) Date: 2009-05-11 17:58
[jon@jaydee Development]$ cat is-strftime-broken.py
#!/usr/bin/env python
import subprocess
import time
date_process = subprocess.Popen(
    ("date", "+%x"), stdout=subprocess.PIPE)
from_date_command = date_process.communicate()[0].rstrip()
from_strftime = time.strftime("%x")
print "Date command returns %s, strftime returns %s" % (
    from_date_command, from_strftime )
[jon@jaydee Development]$ python ./is-strftime-broken.py
Date command returns 11/05/09, strftime returns 05/11/09
msg87584 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2009-05-11 19:52
Please read

http://docs.python.org/library/locale.html

specifically the docs for 'setlocale'. Before you call setlocale,
python's locale is 'C', just like for any C program before it calls
setlocale.

Python 2.6.2 (r262:71600, May  2 2009, 15:06:57) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import locale
>>> import time
>>> time.strftime("%x")
'05/11/09'
>>> locale.setlocale(locale.LC_ALL,"")
'tr_TR.utf-8'
>>> time.strftime("%x")
'11-05-2009'
msg87594 - (view) Author: Jonathan (jonathan.cervidae) Date: 2009-05-11 22:52
Works perfectly now, thank you and sorry for the inaccurate report.
History
Date User Action Args
2009-05-11 22:52:18jonathan.cervidaesetmessages: + msg87594
2009-05-11 19:52:42r.david.murraysetstatus: open -> closed

nosy: + r.david.murray
messages: + msg87584

resolution: not a bug
2009-05-11 17:58:26jonathan.cervidaecreate