#!/usr/bin/env python
#-*- coding:utf-8 -*-
#author: jpuyy.com date
#modified by xx at date
#import time
#from dateutil import tz
from datetime import datetime, timedelta, tzinfo
class GMT8(tzinfo):
delta = timedelta(hours=8)
def utcoffset(self, dt):
return self.delta
def tzname(self, dt):
return "GMT+8"
def dst(self, dt):
return self.delta
class GMT(tzinfo):
delta = timedelta(0)
def utcoffset(self, dt):
return self.delta
def tzname(self, dt):
return "GMT+0"
def dst(self, dt):
return self.delta
a = "2014-12-13T10:42:28.000Z"
from_tzinfo = GMT()
local_tzinfo = GMT8()
gmt_time = datetime.strptime(a, '%Y-%m-%dT%H:%M:%S.%fZ')
gmt_time = gmt_time.replace(tzinfo=from_tzinfo)
local_time = gmt_time.astimezone(local_tzinfo)
print gmt_time
print local_time
Leave a Reply