Passion/Python

시간 관련

sunshout 2008. 10. 6. 17:26

참조: http://pleac.sourceforge.net/pleac_python/datesandtimes.html

현재 시간을 초로 구하기 (Language : python)
#-----------------------------
# Converting DMYHMS to Epoch Seconds
# To work with Epoch Seconds, you need to use the time module

# For the local timezone
t = datetime.datetime.now()
print "Epoch Seconds:", time.mktime(t.timetuple())
#=> Epoch Seconds: 1060199000.0

# For UTC
t = datetime.datetime.utcnow()
print "Epoch Seconds:", time.mktime(t.timetuple())
#=> Epoch Seconds: 1060195503.0
 


from datetime import datetime

d = datetime.now()
d.strftime("%Y-%m-%dT%H:%M:%S-05:00")

'2017-12-08T04:13:48-05:00'



http://knight76.tistory.com/entry/python-pytz%EC%9D%98-%ED%8F%89%EC%96%91%EC%84%9C%EC%9A%B8-%EC%8B%9C%EA%B0%84-%EB%B2%84%EA%B7%B8