赞
踩
1,获取当前秒级别时间戳
- import time
-
- mkt = int(round(time.time()))
-
- print (" 当前时间戳为: %s" % int (round(time.time())
2,获取当前年-月-日 时:分:秒 格式:NNNN-YY-RR HH:FF:SS
- def get_current_datetime_05():
- now = datetime.now()
- year = now.year
- month = now.month
- day = now.day
- hour = now.hour
- minute = now.minute
- second = now.second
-
- formatted_date = f"{year:04d}-{month:02d}-{day:02d} {hour:02d}:{minute:02d}:{second:02d}"
- print(formatted_date)
- return formatted_date
3,获取当前年月
- def formatted_date_06():
- now = datetime.now()
- # 格式化当前年月
- formatted_date1 = now.strftime("%Y-%m")
- return formatted_date1
4、获取毫秒级别时间戳
- def get_millisecond_timestamp_07():
- # 获取当前时间的时间戳,精确到毫秒
- timestamp = int(time.time() * 1000)
- return timestamp
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。