python整理

python实例: 时间换算

2017-05-27  本文已影响18人  随风化作雨

直接上源码:

#!/usr/bin/env python
# -*- coding: utf-8 -*


import datetime

#unix_ts=1439111215

while True:
    input = raw_input("Please input the unix_ts('exit' to exit):")

    try:
        
        if input == 'exit':
            break
        else:
            unix_ts = float(input)
            mytime = datetime.datetime.fromtimestamp(unix_ts)
            print mytime
    except (ValueError,TypeError),diag:
    
        print "your input is not right!"

运行结果:


上一篇 下一篇

猜你喜欢

热点阅读