南强小屋 Design By 杰米
附上代码与运行结果截图:
import time
# 获取当前时间
now = time.localtime()
# 格式化日期
now_ = time.strftime('%Y-%m-%d %H:%M:%S', now)
# 获取当前时间,以时间戳格式
now_stamp = time.time()
# 日期转时间戳
change_to_stamp = time.mktime(time.strptime(now_, "%Y-%m-%d %H:%M:%S"))
# 时间戳转日期
change_to_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(now_stamp))
print(now)
print(now_)
print(now_stamp)
print(change_to_stamp)
print(change_to_time)
运行截图如下:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
南强小屋 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
南强小屋 Design By 杰米
暂无基于python获取本地时间并转换时间戳和日期格式的评论...
