From:http://www.cnblogs.com/65702708/archive/2011/04/17/2018936.html

http://www.wklken.me/posts/2015/03/03/python-base-datetime.html

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 ( - )
%H Hour in -hour format ( - )
%I Hour in -hour format ( - )
%j Day of year as decimal number ( - )
%m Month as decimal number ( - )
%M Minute as decimal number ( - )
%p Current locale's A.M./P.M. indicator for 12-hour clock
%S Second as decimal number ( - )
%U Week of year as decimal number, with Sunday as first day of week ( - )
%w Weekday as decimal number ( - ; Sunday is )
%W Week of year as decimal number, with Monday as first day of week ( - )
%x Date representation for current locale
%X Time representation for current locale
%y Year without century, as decimal number ( - )
%Y Year with century, as decimal number
%z, %Z Time-zone name or abbreviation; no characters if time zone is unknown
%% Percent sign

举一个例子:

ebay中时间格式为‘Sep-21-09 16:34’

则通过下面代码将这个字符串转换成datetime

c = datetime.datetime.strptime('Sep-21-09 16:34','%b-%d-%y %H:%M');

#打印C
c
datetime.datetime(2009, 9, 21, 16, 34)

又如:datetime转换成字符串

datetime.datetime.now().strftime('%b-%d-%y %H:%M:%S');
'Sep-22-09 16:48:08'

最新文章

  1. 漫步ASP.NET MVC的处理管线
  2. react native AsyncStorage的使用
  3. I/O工作机制
  4. jquery插件-表单验证插件-demo
  5. 用DOS命令打开IE浏览器、我的文档等等
  6. iOS开发——UI基础-Xcode资源拷贝
  7. Spring 文章推荐
  8. Ubuntu软件中心打不开,Encountered a section with no Package: header错误之解决
  9. Dialog类介绍
  10. Python 入門語法和類型(转载学习)
  11. jquery easyui读取json文件乱码
  12. MyISAM读写并发优化
  13. 使用openxml读取xml数据
  14. [Locked] Meeting Room I && II
  15. 使用lock_sga和pre_page_sga参数保证SGA常驻物理内存 .
  16. Android UI目录
  17. sql tran, c# SqlTransaction , TransactionScope 的用法
  18. 转 android客户端版本检测更新,服务下载,通知栏显示
  19. @class指令的使用
  20. div始终在底部

热门文章

  1. [LeetCode] Same Tree 深度搜索
  2. 分享C#识别图片上的数字
  3. 查询/删除/建立DB2数据表的主键
  4. 转载自——Json.Net如何在序列化之前修改属性值
  5. HDU5877Weak Pair
  6. validate插件使用
  7. 某考试T1 game
  8. 关于AutoLayout(自动布局)那些事儿
  9. EV根证书
  10. Rebound动画框架简单介绍