Skip to content

Instantly share code, notes, and snippets.

@ZhigangPu
Created March 8, 2019 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZhigangPu/ec1629bbfa0a19fe1d010901b8eea138 to your computer and use it in GitHub Desktop.
Save ZhigangPu/ec1629bbfa0a19fe1d010901b8eea138 to your computer and use it in GitHub Desktop.
time
# 生成时间戳
def get_timestamp(string, mode=1):
if mode==1:
return int(time.mktime(time.strptime(string,"%Y%m%d")))
elif mode==2:
return int(time.mktime(time.strptime(string,'%Y-%m-%d %H:%M:%S')))
# 时间戳转换为日期 mode1:‘年月日’,mode2:'年-月-日 小时:分钟:秒'
def get_dateString(timestamp,mode=1):
date=time.localtime(timestamp)
if mode==1:
return time.strftime('%Y%m%d',date)
elif mode==2:
return time.strftime('%Y-%m-%d %H:%M:%S',date)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment