963 shaares
4 results
tagged
datetime
Sérialiser une date pour avoir: année, mois, jour, heure, minute, seconde, microseconde :
import datetime
datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
>>> '2012-07-22 16:19:00.539570'
A l’inverse, parser une date:
datetime.datetime.strptime('2012-07-22 16:19:00.539570', '%Y-%m-%d %H:%M:%S.%f')
>>> datetime.datetime(2012, 7, 22, 16, 19, 0, 539570)
import datetime
datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
>>> '2012-07-22 16:19:00.539570'
A l’inverse, parser une date:
datetime.datetime.strptime('2012-07-22 16:19:00.539570', '%Y-%m-%d %H:%M:%S.%f')
>>> datetime.datetime(2012, 7, 22, 16, 19, 0, 539570)
The GNU date command in full of goodies but not when it comes to calculate a date or time difference. Here is what I came up with after looking to more than one solution. Code should be self explaining.
The datetime module includes functions and classes for doing date and time parsing, formatting, and arithmetic.
rfc3339.py is a small Python library to format dates to rfc 3339 strings. Useful if you want to add an Atom feed to you site / project. Grab the file, drop it in your python source code, that's it! Licensed under the term of the ISC License a simple, permissive, BSD-like license.