首页 > 编程语言 > 详细

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

时间:2020-05-12 00:38:42      阅读:59      评论:0      收藏:0      [点我收藏+]
首先自定义一个函数,以后只要调用这个函数,就能返回年月日和调用的时间
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中的 “-” 直接换成年月日


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

原文:https://www.cnblogs.com/hua264/p/12873394.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!