首页 > 编程语言 > 详细

python脚本获取时间格式

时间:2018-07-03 16:25:59      阅读:131      评论:0      收藏:0      [点我收藏+]
来源 Python中获取当前日期的格式:https://www.cnblogs.com/wenBlog/p/6023742.html

#!/usr/bin/python
# -*- coding: utf-8 -*-

import time
print (time.strftime("%H:%M:%S"))

## 12 hour format ##
print (time.strftime("%I:%M:%S"))

import time
print (time.strftime("%d/%m/%Y"))

import time
print (time.strftime("%Y%m%d"))

import time
print (time.strftime("%Y%m%d %H:%M:%S"))

输出结果:

14:09:43
02:09:43
03/07/2018
20180703
20180703 14:09:43

或者变成变量:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import time

gaintime = time.strftime("%Y%m%d %H:%M:%S")

print gaintime

python脚本获取时间格式

原文:http://blog.51cto.com/weiruoyu/2135523

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