Revision [2030]

Last edited on 2012-01-12 11:32:21 by KlenwellAdmin
Additions:
====RFC 3339====
reference: http://stackoverflow.com/questions/8556398/generate-rfc-3339-timestamp-in-python
With decimal seconds stripped:
%%(python)
>>> from datetime import datetime
>>> datetime.utcnow().isoformat("T").rsplit('.')[0] + "Z"
'2012-01-12T19:36:34Z'


Revision [1942]

Edited on 2011-10-14 14:06:11 by KlenwellAdmin
Additions:
>>> datetime.now().strftime('It is %H:%M:%S on %d %h %Y')
Deletions:
>>> datetime.today().strftime('It is %H:%M:%S on %d %h %Y')


Revision [1941]

Edited on 2011-10-14 14:01:24 by KlenwellAdmin
Additions:
====Date to String (Date Formatting)====
>>> from datetime import date, datetime
>>> datetime.today().strftime('It is %H:%M:%S on %d %h %Y')
'It is 14:05:17 on 14 Oct 2011'
>>> date.today().strftime('Today is %Y-%m-%d')
'Today is 2011-10-14'


Revision [1553]

Edited on 2010-08-18 07:52:35 by KlenwellAdmin
Additions:
christmas = datetime.strptime('2010-12-25 00:00:00', '%Y-%m-%d %H:%M:%S')
Deletions:
christmas = datetime.strptime('2010-12-25 00:00:00')


Revision [1552]

Edited on 2010-08-18 07:52:02 by KlenwellAdmin
Additions:
christmas_date = christmas.date()
christmas_date_str = str(christmas)


Revision [1551]

Edited on 2010-08-18 07:31:21 by KlenwellAdmin
Additions:
christmas = datetime.strptime('2010-12-25 00:00:00')
christmas_eve = christmas - timedelta(days=1)
Deletions:
birthday = datetime.strptime('%Y-%m-%d %H:%M:%S', '2010-05-22 08:00:00') - timedelta(years=21)


Revision [1550]

Edited on 2010-08-18 07:28:58 by KlenwellAdmin
Additions:
====String to Date====
birthday = datetime.strptime('%Y-%m-%d %H:%M:%S', '2010-05-22 08:00:00') - timedelta(years=21)
from datetime import date, datetime, timedelta
now = datetime.now() - timedelta(days=1)
a_day_ago = now - timedelta(days=1)
a_day_from_now = now + timedelta(days=1)
http://docs.python.org/library/datetime.html#strftime-strptime-behavior
Deletions:
from datetime import date, timedelta


Revision [1495]

Edited on 2010-07-11 23:32:54 by KlenwellAdmin
Additions:
reference: http://docs.python.org/library/datetime.html#tzinfo-objects
For a Google App Engine project I'm working on, I have to sync the app's time zone, which on the App Engine servers is UTC, to a Google Analytic profile's (i.e. site's) time zone, which [[http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55512 defaults to US/Pacific]].
Deletions:
For a Google App Engine project I'm working on, I have to sync the app's time zone, which on the App Engine servers is UTC, to a Google Analytic profile's (i.e. site's) time zone, which [[http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55512 defaults to US/Pacific]]


Revision [1494]

Edited on 2010-07-11 23:29:43 by KlenwellAdmin
Additions:
====Time Zones====
For a Google App Engine project I'm working on, I have to sync the app's time zone, which on the App Engine servers is UTC, to a Google Analytic profile's (i.e. site's) time zone, which [[http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55512 defaults to US/Pacific]]
Sample Code:
from datetime import datetime, timedelta
GA_OFFSET=-8 # PST (offset from UTC -- ignoring DST)
def sync_now():
return datetime.utcnow() + timedelta(hours=GA_OFFSET)
def sync_today():
return sync_now().date()


Revision [1484]

Edited on 2010-07-09 14:16:20 by KlenwellAdmin
Additions:
from datetime import date, timedelta
Deletions:
from datetime import date


Revision [1483]

The oldest known version of this page was created on 2010-07-09 14:05:59 by KlenwellAdmin
Valid XHTML 1.0 TransitionalValid CSSWikkaWiki