码迷,mamicode.com
首页 > 编程语言 > 详细

python脚本获取时间格式

时间:2018-07-03 16:57:46      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:ofo   时间格式   pytho   www.   来源   变量   htm   orm   ref   

来源 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脚本获取时间格式

标签:ofo   时间格式   pytho   www.   来源   变量   htm   orm   ref   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!