from datetime import datetime # 获取当前时间 now = datetime.now() # 获取年、月、日、时、分、秒和毫秒 year = now.year month = now.month day = now.day hour = now.hour minute = now.minute second = now.second millisecond = now.microsecond // 1000 # 毫秒需要除以1000,因为microsecond返回的是微秒 print(f"年: {year}") print(f"月: {month}") print(f"日: {day}") print(f"时: {hour}") print(f"分: {minute}") print(f"秒: {second}") print(f"毫秒: {millisecond}")
######################
标签:python,datetime,毫秒,second,year,print,now,时分秒 From: https://www.cnblogs.com/herd/p/17726626.html