In [1]:
import numpy as np
import pandas as pd

time zone


In [6]:
rng = pd.date_range('3-6-2016 00:00', periods=15, freq='d')
rng


Out[6]:
DatetimeIndex(['2016-03-06', '2016-03-07', '2016-03-08', '2016-03-09',
               '2016-03-10', '2016-03-11', '2016-03-12', '2016-03-13',
               '2016-03-14', '2016-03-15', '2016-03-16', '2016-03-17',
               '2016-03-18', '2016-03-19', '2016-03-20'],
              dtype='datetime64[ns]', freq='D')

In [8]:
print(rng.tz)


None

In [10]:
rng1 = pd.date_range('3-6-2016 00:00', 
                     periods=15, 
                     freq='d', 
                     tz='Europe/London')
rng1


Out[10]:
DatetimeIndex(['2016-03-06', '2016-03-07', '2016-03-08', '2016-03-09',
               '2016-03-10', '2016-03-11', '2016-03-12', '2016-03-13',
               '2016-03-14', '2016-03-15', '2016-03-16', '2016-03-17',
               '2016-03-18', '2016-03-19', '2016-03-20'],
              dtype='datetime64[ns, Europe/London]', freq='D')

In [11]:
rng1.tz


Out[11]:
<DstTzInfo 'Europe/London' LMT-1 day, 23:59:00 STD>

In [12]:
from pytz import common_timezones, all_timezones
print(len(common_timezones))


439

In [13]:
print(len(all_timezones))


591

In [16]:
common_timezones[0:5]


Out[16]:
['Africa/Abidjan',
 'Africa/Accra',
 'Africa/Addis_Ababa',
 'Africa/Algiers',
 'Africa/Asmara']

In [17]:
all_timezones[0:5]


Out[17]:
['Africa/Abidjan',
 'Africa/Accra',
 'Africa/Addis_Ababa',
 'Africa/Algiers',
 'Africa/Asmara']

In [19]:
# not in common
set(all_timezones) - set(common_timezones)


Out[19]:
{'Africa/Asmera',
 'Africa/Timbuktu',
 'America/Argentina/ComodRivadavia',
 'America/Atka',
 'America/Buenos_Aires',
 'America/Catamarca',
 'America/Coral_Harbour',
 'America/Cordoba',
 'America/Ensenada',
 'America/Fort_Wayne',
 'America/Indianapolis',
 'America/Jujuy',
 'America/Knox_IN',
 'America/Louisville',
 'America/Mendoza',
 'America/Montreal',
 'America/Porto_Acre',
 'America/Rosario',
 'America/Santa_Isabel',
 'America/Shiprock',
 'America/Virgin',
 'Antarctica/South_Pole',
 'Asia/Ashkhabad',
 'Asia/Calcutta',
 'Asia/Chongqing',
 'Asia/Chungking',
 'Asia/Dacca',
 'Asia/Harbin',
 'Asia/Istanbul',
 'Asia/Kashgar',
 'Asia/Katmandu',
 'Asia/Macao',
 'Asia/Rangoon',
 'Asia/Saigon',
 'Asia/Tel_Aviv',
 'Asia/Thimbu',
 'Asia/Ujung_Pandang',
 'Asia/Ulan_Bator',
 'Atlantic/Faeroe',
 'Atlantic/Jan_Mayen',
 'Australia/ACT',
 'Australia/Canberra',
 'Australia/LHI',
 'Australia/NSW',
 'Australia/North',
 'Australia/Queensland',
 'Australia/South',
 'Australia/Tasmania',
 'Australia/Victoria',
 'Australia/West',
 'Australia/Yancowinna',
 'Brazil/Acre',
 'Brazil/DeNoronha',
 'Brazil/East',
 'Brazil/West',
 'CET',
 'CST6CDT',
 'Canada/Saskatchewan',
 'Canada/Yukon',
 'Chile/Continental',
 'Chile/EasterIsland',
 'Cuba',
 'EET',
 'EST',
 'EST5EDT',
 'Egypt',
 'Eire',
 'Etc/GMT',
 'Etc/GMT+0',
 'Etc/GMT+1',
 'Etc/GMT+10',
 'Etc/GMT+11',
 'Etc/GMT+12',
 'Etc/GMT+2',
 'Etc/GMT+3',
 'Etc/GMT+4',
 'Etc/GMT+5',
 'Etc/GMT+6',
 'Etc/GMT+7',
 'Etc/GMT+8',
 'Etc/GMT+9',
 'Etc/GMT-0',
 'Etc/GMT-1',
 'Etc/GMT-10',
 'Etc/GMT-11',
 'Etc/GMT-12',
 'Etc/GMT-13',
 'Etc/GMT-14',
 'Etc/GMT-2',
 'Etc/GMT-3',
 'Etc/GMT-4',
 'Etc/GMT-5',
 'Etc/GMT-6',
 'Etc/GMT-7',
 'Etc/GMT-8',
 'Etc/GMT-9',
 'Etc/GMT0',
 'Etc/Greenwich',
 'Etc/UCT',
 'Etc/UTC',
 'Etc/Universal',
 'Etc/Zulu',
 'Europe/Belfast',
 'Europe/Nicosia',
 'Europe/Tiraspol',
 'GB',
 'GB-Eire',
 'GMT+0',
 'GMT-0',
 'GMT0',
 'Greenwich',
 'HST',
 'Hongkong',
 'Iceland',
 'Iran',
 'Israel',
 'Jamaica',
 'Japan',
 'Kwajalein',
 'Libya',
 'MET',
 'MST',
 'MST7MDT',
 'Mexico/BajaNorte',
 'Mexico/BajaSur',
 'Mexico/General',
 'NZ',
 'NZ-CHAT',
 'Navajo',
 'PRC',
 'PST8PDT',
 'Pacific/Johnston',
 'Pacific/Ponape',
 'Pacific/Samoa',
 'Pacific/Truk',
 'Pacific/Yap',
 'Poland',
 'Portugal',
 'ROC',
 'ROK',
 'Singapore',
 'Turkey',
 'UCT',
 'US/Aleutian',
 'US/East-Indiana',
 'US/Indiana-Starke',
 'US/Michigan',
 'US/Samoa',
 'Universal',
 'W-SU',
 'WET',
 'Zulu'}

In [22]:
t_naive = pd.Timestamp('2016-05-21 8:30')
t_naive


Out[22]:
Timestamp('2016-05-21 08:30:00')

In [26]:
t = t_naive.tz_localize(tz='US/Hawaii')
t


Out[26]:
Timestamp('2016-05-21 08:30:00-1000', tz='US/Hawaii')

In [27]:
t.tz_convert('Asia/Tokyo')


Out[27]:
Timestamp('2016-05-22 03:30:00+0900', tz='Asia/Tokyo')

ambiguous time


In [31]:
# dayligh saving
rng = pd.date_range('2016-03-10', periods=10, tz='US/Central')
rng


Out[31]:
DatetimeIndex(['2016-03-10 00:00:00-06:00', '2016-03-11 00:00:00-06:00',
               '2016-03-12 00:00:00-06:00', '2016-03-13 00:00:00-06:00',
               '2016-03-14 00:00:00-05:00', '2016-03-15 00:00:00-05:00',
               '2016-03-16 00:00:00-05:00', '2016-03-17 00:00:00-05:00',
               '2016-03-18 00:00:00-05:00', '2016-03-19 00:00:00-05:00'],
              dtype='datetime64[ns, US/Central]', freq='D')

In [ ]: