AutoFramework/Base/Class/Time.py

16 lines
451 B
Python
Raw Normal View History

2022-07-01 22:48:22 +08:00
import time
def time_format(fmt='%Y-%m-%d %H:%M:%S', ts=None):
return time.strftime(fmt, time.localtime(ts))
def time_make(datetime_format='', dt=''):
return time.mktime(time.strptime(dt, datetime_format))
if __name__ == '__main__':
# Example.
print(time_format(fmt='%Y年%m月%d%H:%M:%S'))
print(time_format(fmt='%Y年%m月%d%H:%M:%S', ts=1640012345))
print(time_make('%Y-%m-%d %H:%M:%S', '2021-12-20 22:59:05'))