Hello sekitaka.
Using the timedelta object of the datetime module of python, you can easily add or subtract the date and time and calculate the difference between the two datetime.
# coding:utf-8
# !/usr/bin/python
from datetime import datetime,timedelta
import pytz
#Addition and subtraction based on the current time
timezone = pytz.timezone('Asia/Tokyo')
now = datetime.now(tz=timezone)
delta = timedelta(days=+1)
tomorrow = now + delta
print "now{0}".format(now)
print "One day later{0}".format(tomorrow)
#Calculate the difference between two dates
delta = tomorrow - now
print "The difference is{0}Day".format(delta.days)
For more detailed usage, please refer to Official Document.
Recommended Posts