该代码是一个时间相关的功能模块,提供了一些获取当前时间的函数。
Report_time()
函数返回当前时间的格式化字符串,例如 "20240110114512"。Y_M_D_h_m_s_time()
函数返回当前时间的年、月、日、时、分、秒的元组格式。Y_M_D_h_m_s()
函数返回当前时间的格式化字符串,例如 "2024/01/10 11:45:12"。Y_M_D()
函数返回当前日期的格式化字符串,例如 "2024/01/10"。Y_M_D_2()
函数返回当前日期的格式化字符串,例如 "2024-01-10"。
如果你运行这段代码,将会打印出当前时间和日期的不同格式。
import time
def Report_time():
cur = time.time()
local_time = time.localtime(cur)
current = time.strftime("%Y%m%d%H%M%S", local_time)
return current
def Y_M_D_h_m_s_time():
cur = time.time()
local_time = time.localtime(cur)
Y = time.strftime("%Y", local_time) # 年
M = time.strftime("%m", local_time) # 月
D = time.strftime("%d", local_time) # 日
h = time.strftime("%H", local_time) # 时
m = time.strftime("%M", local_time) # 分
s = time.strftime("%S", local_time) # 秒
return Y, M, D, h, m, s
def Y_M_D_h_m_s():
cur = time.time()
local_time = time.localtime(cur)
current = time.strftime("%Y/%m/%d %H:%M:%S", local_time)
return current
def Y_M_D():
cur = time.time()
local_time = time.localtime(cur)
current = time.strftime("%Y/%m/%d", local_time)
return current
def Y_M_D_2():
cur = time.time()
local_time = time.localtime(cur)
current = time.strftime("%Y-%m-%d", local_time)
return current
if __name__ == '__main__':
print(Report_time())
print(Y_M_D_h_m_s_time())
print(Y_M_D())
print(Y_M_D_2())