对于像'Wed, 11 Apr 2012 09:37:05 +0800'的时间格式化可如下解:

>>> date='Wed, 11 Apr 2012 09:37:05 +0800'
>>> dd=datetime.datetime.strptime(date,'%a, %d %b %Y %H:%M:%S %z')
>>> dd.strftime('%Y-%m-%d %H:%M:%S')

Python格式化日期时间的函数为datetime.datetime.strftime();由字符串转为日期型的函数为:datetime.datetime.strptime(),两个函数都涉及日期时间的格式化字符串,列举如下:

%a Abbreviated weekday name
%A Full weekday name
%b Abbreviated month name
%B Full month name
%c Date and time representation appropriate for locale
%d Day of month as decimal number (01 - 31)
%H Hour in 24-hour format (00 - 23)
%I Hour in 12-hour format (01 - 12)
%j Day of year as decimal number (001 - 366)
%m Month as decimal number (01 - 12)
%M Minute as decimal number (00 - 59)
%p Current locale's A.M./P.M. indicator for 12-hour clock
%S Second as decimal number (00 - 59)
%U Week of year as decimal number, with Sunday as first day of week (00 - 51)
%w Weekday as decimal number (0 - 6; Sunday is 0)
%W Week of year as decimal number, with Monday as first day of week (00 - 51)
%x Date representation for current locale
%X Time representation for current locale
%y Year without century, as decimal number (00 - 99)
%Y Year with century, as decimal number
%z, %Z Time-zone name or abbreviation; no characters if time zone is unknown
%% Percent sign 

Python 的时间格式化相关推荐

  1. python 日期格式月份不加前导,Python datetime时间格式化去掉前导0

    Python datetime时间格式化去掉前导0 Python时间格式化的时候,去掉前导0的: dt = datetime.now() print dt.strftime('%-H') #结果是: ...

  2. 1、Python 日期时间格式化输出

    今天帮朋友写自动化脚本,又需要用格式化日期,又忘记怎么写了,还是写到自己博客里面,方便日后需要的时候看一眼吧.So,临时加一篇 Python 的文章. 1.Python的time模块 import t ...

  3. python linux 时间格式化,Python3 格式化日期

    导读 Python 提供了一个 time 和 calendar 模块可以用于格式化日期和时间. 我们可以使用 time 模块的 strftime 方法来格式化日期,: time.strftime(fo ...

  4. python格式化输出日期_1、Python 日期时间格式化输出

    今天帮朋友写自动化脚本,又需要用格式化日期,又忘记怎么写了,还是写到自己博客里面,方便日后需要的时候看一眼吧.So,临时加一篇 Python 的文章. 1.Python的time模块 importti ...

  5. python数据清洗-时间格式化

    数据清洗-时间格式化 1.字符串转时间 from datetime import datetime t = '2020年11月11日15:04:41' time = datetime.strptime ...

  6. python linux 时间格式化,Python中的时间日期转换

    Python关于时间日期有两个库datetime和time,于是我们要在四种格式之间转换: datetime.datetime对象 datetime.datetime.now() time.struc ...

  7. Python 日期时间格式化输出,带年、月、日、时、分、秒

    使用time模块,输出格式化日期时间字符串: import time date_str = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()) p ...

  8. python时间日期格式,python日期时间格式化

    1.将字符串的时间转换为时间戳 方法: a = "2018-07-05 23:40:00" #将其转换为时间数组 import time timeArray = time.strp ...

  9. scrapy笔记——python的时间转换

    1 import datetime 2 GMT_FORMAT = '%M %H %d %m %w' 3 datetime.datetime.utcnow().strftime(GMT_FORMAT) ...

最新文章

  1. cocos2dx 自学记录(4)-- 写一个自己的界面
  2. 取消管理员取得所有权_win7管理员取得所有权批处理 - 卡饭网
  3. cac会议投稿难度大吗_发表 SCI 论文有多难?
  4. MySQL中的外键约束
  5. DES加密解密与AES加密解密
  6. [Android]使用Dagger 2进行依赖注入 - Producers(翻译)
  7. JavaScript的面向对象特性
  8. 参加 CSDN 2009 英雄大会有感(一)
  9. VUE3(setup响应式函数系统API)
  10. 【mmdetection3d】——3D 目标检测 KITTI 数据集
  11. PDF编辑器哪个好,如何把PDF文件拆分成多个文件
  12. 15分钟快速搭建属于自己的网站
  13. 正则表达式匹配书名号内容
  14. 计算机专业29岁研究生毕业,26岁,你还会考研吗?毕业后都奔三了!_计算机考研科目...
  15. d3d透视逆向篇:第5课:D3D9游戏黑屏优化2 DrawIndexedPrimitive
  16. 论文阅读:UER: An Open-Source Toolkit for Pre-training Models
  17. C#京东模拟注册~滑块轨迹算法~EID~密码RSA加密
  18. 计算机无法播放视频,电脑自带播放器无法播放视频怎么办
  19. 对json数据进行处理的小程序总结
  20. ubuntu LibreOffice writer的基本操作

热门文章

  1. 零窗口探测怎么抓包_万事俱备,只待“窗口”!航天任务中的重要环节:“发射窗口”!...
  2. 酱油和gbt酱油哪个好_酱油越贵越好?认准瓶身这4处,轻松挑到好酱油!
  3. web开发常用工具介绍
  4. Java虚拟机栈介绍
  5. 《深入理解java虚拟机》第2章 Java内存区域与内存溢出异常
  6. springcloud config服务端配置(一)
  7. 产品经理需要掌握的9种共性推荐策略
  8. 美团和支付宝大战在所难免
  9. 这样准备,面试成功率提升30%
  10. 动态分配方式计算学生成绩