python time,datetime,string转换
2013-02-20 13:44
344 查看
#把datetime转成字符串
def datetime_toString(dt):
return dt.strftime("%Y-%m-%d %H:%M:%S")
#把字符串转成datetime
def string_toDatetime(string):
return datetime.strptime(string, "%Y-%m-%d %H:%M:%S")
#把字符串转成时间戳形式
def string_toTimestamp(strTime):
return time.mktime(time.strptime(strTime,'%Y-%m-%d %H:%M:%S'))
#把时间戳转成字符串形式
def timestamp_toString(stamp):
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(stamp))
#把datetime类型转外时间戳形式
def datetime_toTimestamp(dateTime):
return time.mktime(dateTime.timetuple())
#时间戳转datetime形式
datetime.datetime.fromtimestamp(1345270963)
def datetime_toString(dt):
return dt.strftime("%Y-%m-%d %H:%M:%S")
#把字符串转成datetime
def string_toDatetime(string):
return datetime.strptime(string, "%Y-%m-%d %H:%M:%S")
#把字符串转成时间戳形式
def string_toTimestamp(strTime):
return time.mktime(time.strptime(strTime,'%Y-%m-%d %H:%M:%S'))
#把时间戳转成字符串形式
def timestamp_toString(stamp):
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(stamp))
#把datetime类型转外时间戳形式
def datetime_toTimestamp(dateTime):
return time.mktime(dateTime.timetuple())
#时间戳转datetime形式
datetime.datetime.fromtimestamp(1345270963)
相关文章推荐
- 【python】time,datetime,string相互转换
- ]python time, datetime, string, timestamp相互转换
- 【python】time,datetime,string相互转换
- 【python】----- time,datetime,string相互转换
- python time, datetime, string, timestamp相互转换
- 【python】time,datetime,string相互转换
- python中time类型,datetime类型的关系与互相转换
- python中date、datetime、string的相互转换
- Python中struct_time、Timestrap、String之间转换
- python 时间戳 datetime string 转换
- python time和datetime的常用转换处理
- Python 调用datetime或者time获取时间的时候以及时间转换,最好设置一下时区 否则会出现相差8个小时的情况
- python中date、datetime、string的相互转换
- Python中time模块和datetime模块的常用操作以及几种常用时间格式间的转换
- python时间模块time,时间戳,结构化时间,字符串时间,相互转换,datetime
- python中date、datetime、string的相互转换
- python整理十八——datetime与time之间的转换
- python中date、datetime、string的相互转换
- Python datetime / time 转换
- python time和datetime的常用转换处理