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'))