Question

Here is UTC time:

now_utc = datetime.datetime.now(timezone('UTC'))

Here is the time zone of Tokyo:

 tz = Asia/Tokyo

So...using pytz how to I get the local time on Japan?

Was it helpful?

Solution

This should work:

now_utc.astimezone(timezone('Asia/Tokyo'))

OTHER TIPS

Try this:

import pytz
import datetime

a = datetime.datetime.now() # UTC
b = datetime.datetime.now(tz=pytz.timezone('Asia/Tokyo')) # for Japan time zone

Output example

a:

datetime.datetime(2015, 5, 27, 9, 39, 48, 451388)

b:

datetime.datetime(2015, 5, 27, 18, 37, 28, 78739, tzinfo=<DstTzInfo 'Asia/Tokyo' JST+9:00:00 STD>)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top