Python 日期格式化 及 schwartzian排序
2014-02-28 11:31
399 查看
__author__ = 'root' import datetime import time import copy # 12/Dec/2012:23:59:50 # 12/Sep/2012:23:58:50 # 11/Sep/2012:23:59:50 # 19/Sep/2012:23:58:50 def getTime(dtstr): print dtstr time = datetime.datetime.strptime(dtstr, '%d/%b/%Y:%H:%M:%S') return time.strftime('%Y%m%d%H%M%S') lines = open('datefmt.txt').readlines() lines = [i.strip() for i in lines] line_copy = copy.copy(lines) lines = [getTime(line) for line in lines] lines.sort() for line in lines: print line line_copy.sort() for item in line_copy: print item
12/Dec/2012:23:59:50 12/Sep/2012:23:58:50 11/Sep/2012:23:59:50 19/Sep/2012:23:58:50 20120911235950 20120912235850 20120919235850 20121212235950 11/Sep/2012:23:59:50 12/Dec/2012:23:59:50 12/Sep/2012:23:58:50 19/Sep/2012:23:58:50
相关文章推荐
- Python SocketServer源码分析
- python基于mysql的用户认证
- Python读书笔记第十二章:异常
- Python读书笔记第十一章:输入/输出
- 使用python实现观察者思想
- python urllib2教程
- python入门地址
- Python基础函数学习笔记(三)
- 深入学习python(三) 闭包(Decorator)与装饰器(Closure)
- python抓取网页中的图片示例
- windows下python模拟鼠标点击和键盘输示例
- python发邮件实例
- python调用sendcloud接口实现邮件批量发送收取及url回调 推荐
- How to Install Pygame to Python 3 on Ubuntu
- 我对李杰的python YY公开课不满意
- Python初体验:三句话写个刷微博、博客、空间等的小爬虫
- Python中的除法
- Exercise 6: 字符串
- python中文json串创建与解析
- 优秀Python学习资源收集汇总(强烈推荐)