Difference between revisions of "Datetime"

From PeformIQ Upgrade
Jump to navigation Jump to search
(New page: =Python datetime Module Usage= <pre> from datetime import datetime # ts = datetime.strptime('10:13:15 2006-03-07', '%H:%M:%S %Y-%m-%d') ts = datetime.now().strftime('%Y%m%d%H%M%S'...)
 
Line 1: Line 1:
=Python datetime Module Usage=
=Python datetime Module Usage=
Some fragments of recent usage to remind me of some of the nuances of usage!


<pre>
<pre>
Line 8: Line 10:
   ts = datetime.now().strftime('%Y%m%d%H%M%S')
   ts = datetime.now().strftime('%Y%m%d%H%M%S')
</pre>
</pre>
<pre>
      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
</pre>
<pre>
      'ReminderDateTime'        : datetime(*strptime(ctx.locals.ReminderDateTime, '%Y-%m-%d')[0:6]) + timedelta(minutes=int(ctx.locals.ReminderTime)),
</pre>
==Python DOcumentation==
* http://www.python.org/doc/2.5/lib/node85.html


[[category:Python]]
[[category:Python]]

Revision as of 14:17, 9 March 2008

Python datetime Module Usage

Some fragments of recent usage to remind me of some of the nuances of usage!

  from datetime import datetime

  # ts = 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

      'ReminderDateTime'        : datetime(*strptime(ctx.locals.ReminderDateTime, '%Y-%m-%d')[0:6]) + timedelta(minutes=int(ctx.locals.ReminderTime)),

Python DOcumentation