Skip to content

Instantly share code, notes, and snippets.

@lazybios
Last active August 29, 2015 14:12
Show Gist options
  • Save lazybios/45124ae345727a0e399e to your computer and use it in GitHub Desktop.
Save lazybios/45124ae345727a0e399e to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# coding: utf-8
'''转换时间戳为实际时间 & 格式化时间'''
import time
import sys
if __name__ == "__main__":
if len(sys.argv) > 1:
print sys.argv[1],time.strftime("%H:%M:%S",time.localtime(float(sys.argv[1])))
else:
print "format error ex: python xx.py 1419918180"
#格式化指定时间戳(非当前时间)
val = time.time()
time.strftime('%H:%M_%Y%m%d',time.gmtime(val))
#=> 14:21_20150130
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment