分类: Python/Ruby
2012-02-09 14:58:55
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Last modified: Thu 09 Feb 2012 02:52:49 PM CST [dev]
"""docstring
"""
__revision__ = '0.1'
import time
import datetime
#获得某个时间的时间戳
s = datetime.datetime(2012,2,9,12,0,0)
print "s:%s" % s
print "timestap:%s" % time.mktime(s.timetuple())
#时间字符串转成timestamp
t = '2012-02-09 12:00:00'
print "t:%s" % t
nt = time.strptime( t, "%Y-%m-%d %X" )
print "timestamp of %s is %s" % ( t,time.mktime(datetime.datetime(*nt[:6]).timetuple()))
print "本地当前时间的时间戳:%s" % time.time()
#格式化成时间 '2009-01-01 12:30:00'
now = time.localtime() #time.struct_time结构的当前时间
nt = time.strftime("%Y-%m-%d %X",now )
print 'time of timestamp %s is %s' % (now,nt)
#print time.mktime(nt.timetuple())