morfizm (morfizm) wrote,
morfizm
morfizm

  • Mood:

More Python gotchas

from datetime import datetime
from dateutil.relativedelta import relativedelta 
dt = datetime.strptime('2012-06-01T01:02:03', '%Y-%m-%dT%H:%M:%S')
print dt                                      # 2012-06-01 01:02:03
print dt + relativedelta(month=1, second=0)   # 2012-01-01 01:02:00
print dt + relativedelta(months=1, second=0)  # 2012-07-01 01:02:00
print dt + relativedelta(months=0, second=1)  # 2012-06-01 01:02:01 
print dt + relativedelta(months=0, seconds=1) # 2012-06-01 01:02:04
Tags: in english, software development
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 7 comments