Chinaunix首页 | 论坛 | 博客
  • 博客访问: 346162
  • 博文数量: 135
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1106
  • 用 户 组: 普通用户
  • 注册时间: 2013-03-20 09:56
文章分类

全部博文(135)

文章存档

2017年(3)

2016年(18)

2015年(69)

2014年(39)

2013年(6)

我的朋友

分类: Python/Ruby

2015-03-02 14:05:45

转载:
import time
import datetime


def ISOString2Time(s):
    '''
    convert a ISO format time to second
    from:2006-04-12 16:46:40 to:23123123
    把一个时间转化为秒
    '''
    d = datetime.datedatetime.strptime(s, "%Y-%m-%d %H:%M:%S")
    return time.mktime(d.timetuple())


def Time2ISOString(s):
    '''
    convert second to a ISO format time
    from: 23123123 to: 2006-04-12 16:46:40
    把给定的秒转化为定义的格式
    '''
    return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(float(s)))

if __name__ == '__main__':
    a = "2013-08-26 16:58:00"
    b = ISOString2Time(a)
    print b
    c = Time2ISOString(b)
    print c


阅读(577) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~