python中函数返回年月日和时间


首先自定义一个函数,以后只要调用这个函数,就能返回年月日和调用的时间
def logger():
  #
返回年月日和调用的时间
    import time
time_format='%Y-%m-%d %X '
time_current= time.strftime(time_format )
return time_current

print(logger())
with open('a.txt','a+',encoding= 'utf-8') as f:

f.write('{times} write next'.format(times= logger() ) )
---------------------------------------------------------------------
%X(注意是大写的X)相当于
%H:%M:%S;想要输出年月日的格式,只要把logger中的 “-” 直接换成年月日



免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM