#Exemple de notation de base ISO 8601) "20140526T123456+0900"
jstnow().strftime('%Y%m%dT%H%M%d%z')
#Exemple de notation étendue ISO 8601) "2014-05-26T12:34:56+0900"
jstnow().strftime('%Y-%m-%dT%H:%M:%d%z')
#Exemple de notation étendue ISO 8601) "2014-05-26T12:34:56.123000+0900"
jstnow().isoformat()
from datetime import *
def jstnow():
# JST timezone(+0900)
class JST(tzinfo):
def utcoffset(self, dt):
return timedelta(hours=9)
def dst(self, dt):
return timedelta(0)
return datetime.now(JST())
Implémentation pour calculer explicitement la différence avec UTC
from datetime import *
def jstnow():
# UTC tzinfo
class UTC(tzinfo):
def utcoffset(self, dt):
return timedelta(hours=0)
def dst(self, dt):
return timedelta(0)
# JST timezone(+0900)
class JST(tzinfo):
def utcoffset(self, dt):
return timedelta(hours=9)
def dst(self, dt):
return timedelta(0)
return datetime.utcnow().replace(tzinfo=UTC()).astimezone(JST())
Recommended Posts