Difference between revisions of "Datetime"
Jump to navigation
Jump to search
PeterHarding (talk | contribs) |
PeterHarding (talk | contribs) |
||
Line 6: | Line 6: | ||
from datetime import datetime | from datetime import datetime | ||
dt = datetime.strptime('10:13:15 2006-03-07', '%H:%M:%S %Y-%m-%d') | |||
ts = datetime.now().strftime('%Y%m%d%H%M%S') | ts = datetime.now().strftime('%Y%m%d%H%M%S') |
Revision as of 15:55, 27 May 2008
Python datetime Module Usage
Some fragments of recent usage to remind me of some of the nuances of usage!
from datetime import datetime dt = datetime.strptime('10:13:15 2006-03-07', '%H:%M:%S %Y-%m-%d') ts = datetime.now().strftime('%Y%m%d%H%M%S')
rdt = task.fields.ReminderDateTime if rdt: ctx.locals.ReminderDate = rdt.strftime('%Y-%m-%d') ctx.locals.ReminderTime = rdt.hour * 60 + rdt.minute else: ctx.locals.ReminderDate = ctx.locals.Today ctx.locals.ReminderTime = 630
from time import strptime ... 'ReminderDateTime' : datetime(*strptime(ctx.locals.ReminderDateTime, '%Y-%m-%d')[0:6]) + timedelta(minutes=int(ctx.locals.ReminderTime)),