py3k: datetime resolution / isoformat

MRAB python at mrabarnett.plus.com
Sat Feb 26 03:54:22 CET 2011


On 26/02/2011 02:21, spam at uce.gov wrote:
>
> When I do:
>
> datetime.datetime.now().isoformat(' ')
>
> I get the time with the microseconds. The docs says:
> "if microsecond is 0 YYYY-MM-DDTHH:MM:SS+HH:MM".
>
> How do I set microsecond to 0?
>
>  >>> datetime.datetime.microsecond = 0
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: can't set attributes of built-in/extension type
> 'datetime.datetime'
>
>
>  >>> datetime.datetime.resolution = (0, 0, 0)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> TypeError: can't set attributes of built-in/extension type
> 'datetime.datetime'
>
> Do I need to create my own class to extend datetime.datetime?
>
You could just truncate the result:

     datetime.datetime.now().isoformat(' ')[ : 19]



More information about the Python-list mailing list