[issue1982] Feature: extend strftime to accept milliseconds
Wang Chun
report at bugs.python.org
Wed Oct 29 10:53:56 CET 2008
Wang Chun <yaohua2000 at gmail.com> added the comment:
Ruby recently added support of millisecond and nanosecond to strftime.
This is their changeset:
http://redmine.ruby-lang.org/repositories/revision/ruby-19?rev=18731
To use the extended strftime, one can do:
>> Time.now.strftime('%Y-%m-%dT%H:%M:%S.%L%z')
.. "2008-10-29T17:46:03.895+0800"
In the current implementation of Python, both datetime and time modules
have strftime. Like in Ruby, the strftime in datetime module is a
method. But the strftime in time module is a function, which takes time
value to be formatted from argument, and which must be a 9-tuple
returned by gmtime or localtime. No microsecond data in the tuple,
unfortunately.
I think as the first step we can make datetime.datetime.strftime do
microsecond. I prefer microsecond to milli- or micro- second because it
is something from the the system.
The current Ruby implementation use %L or %3N for millisecond, %6N for
microsecond, and %N or %9N for nanosecond. I am not sure where they came
from. Hope there can be some widely accepted standard.
----------
nosy: +wangchun
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue1982>
_______________________________________
More information about the Python-bugs-list
mailing list