标签:turn import 调用 格式化 _for gen strftime cal mes
import time
# =====封装函数:格式化时间转成时间戳======
def format_time_to_timestamp(format_time=None):
if format_time:
time_tuple = time.strptime(format_time,‘%Y-%m-%d %X‘)
result = time.mktime(time_tuple)
return int(result)
return int(time.time())
#查看调用结果
print(format_time_to_timestamp())
print(format_time_to_timestamp(‘2009-10-10 18:01:11‘))
# ==========封装函数:时间戳转换成格式化时间==========
def timestamp_to_format_time(timestamp=None,format=‘%Y-%m-%d %X‘):
if timestamp:
time_tuple = time.localtime(timestamp)
result = time.strftime(format,time_tuple)
return result
else:
return time.strftime(format)
#查看调用结果
print(timestamp_to_format_time())
print(timestamp_to_format_time(1255168871))
标签:turn import 调用 格式化 _for gen strftime cal mes
原文地址:https://www.cnblogs.com/xuexizongjie/p/10800359.html