C'est La Vie

    人生无彩排,每一天都是现场直播!

    Python中,时间字符串与时间戳的互相转换

    时间字符串转换为时间戳: import time timestring = '2012-05-15 17:12 […]

    时间字符串转换为时间戳:

    import time
    timestring = '2012-05-15 17:12:37'
    timestamp = int(time.mktime(time.strptime(timestring, '%Y-%m-%d %H:%M:%S')))
    print timestamp

    时间戳转换为时间字符串:

    import time
    struct_time = time.localtime(1337073342)
    timestring = time.strftime('%Y-%m-%d %H:%M:%S',struct_time)
    print timestring

    One Comment

    发表回复

    您的电子邮箱地址不会被公开。 必填项已用*标注