代码如下:
#!/usr/bin/env python
# coding=utf-8
"""
www.cdsy.xyz
"""
import time
import datetime
get_now_timestamp = lambda: int(time.time())
'''最常用---获取当前10位时间戳,精确到秒'''
get_now_milli_time = lambda: int(time.time() * 1000)
'''当前13位时间戳,精确到毫秒'''
get_now_micro_time = lambda: int(time.time() * 10 ** 6)
'''当前16位时间戳,精确到微秒'''
zero_second_today = lambda: int(time.mktime(datetime.date.today().timetuple()))
'''取当天日期的00:00:00并转为10位时间戳'''
now_day = lambda timestamp: time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timestamp))
'''入参:时间戳, 转为日期'''
date_to_timestamp = lambda date: int(time.mktime(datetime.datetime.strptime(date, "%Y-%m-%d %H:%M:%S").timetuple()))
'''入参:日期, 转为时间戳'''
get_UTC_time_in_ISO_format = lambda: datetime.datetime.utcnow().isoformat()
'''ISO格式的格林尼治标准时间(UTC) 格式如2020-07-02T08:56:47.564446 '''
get_CST_time_in_ISO_format = lambda: datetime.datetime.now().isoformat()
'''ISO格式的北京(China Standard Time)时间 格式如2020-07-02T08:56:47.564446 '''
get_now_noc_format_date = lambda: time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(get_now_timestamp()))
'''自定义ISO日期格式: 丢弃秒的小数点后的数据,例如2020-06-13T03:09:31 '''
sleep = lambda second: time.sleep(second)
'''等待: 单位秒'''
if __name__ == '__main__':
print("当前10位时间戳:", get_now_timestamp())
print("指定日期转为时间戳:", date_to_timestamp("2020-01-24 10:10:00"))
print("指定时间戳转为日期:", now_day(1579531800))
print(get_now_milli_time(), get_now_timestamp())
print(get_UTC_time_in_ISO_format())
print(get_now_noc_format_date())
print(get_CST_time_in_ISO_format())
print(zero_second_today())
print(get_now_micro_time())