python实例: 时间换算

直接上源码:

#!/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!"

运行结果:

《python实例: 时间换算》

    原文作者:随风化作雨
    原文地址: https://www.jianshu.com/p/bb8b41ef45e7
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞