Created
March 8, 2019 08:50
-
-
Save ZhigangPu/ec1629bbfa0a19fe1d010901b8eea138 to your computer and use it in GitHub Desktop.
time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 生成时间戳 | |
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