直接上源碼:
#!/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!"
運(yùn)行結(jié)果: