Chinaunix首页 | 论坛 | 博客
  • 博客访问: 339552
  • 博文数量: 79
  • 博客积分: 3053
  • 博客等级: 中校
  • 技术积分: 861
  • 用 户 组: 普通用户
  • 注册时间: 2006-02-27 20:43
文章分类

全部博文(79)

文章存档

2012年(3)

2011年(21)

2010年(15)

2009年(40)

分类: 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())

阅读(4647) | 评论(0) | 转发(0) |
0

上一篇:turbogears2.1控制器-1

下一篇:没有了

给主人留下些什么吧!~~