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实例: 时间换算_第1张图片

你可能感兴趣的:(python实例: 时间换算)