python解析时间格式脚本
对于这种时间格式:發表於: 星期一 五月 28, 2012 6:59 am
import re
INPUT = "發表於: 星期一 五月 28, 2012 6:59 am 文章主題: 對《大話新聞》改組的誠心思考/蔬菜麵"
pattern = re.compile(r'[\d]+')
b = re.findall(pattern, INPUT)
a = INPUT.split(' ')
monthdict = {"一月": "","二月": "", "三月": "", "四月": "", "五月": "", "六月": "",
"七月": "", "八月": "", "九月": "", "十月": "", "十一月": "", "十二月": ""}
year = a[4]
month = monthdict[a[2]]
day = b[0]
if a[6] == 'pm':
hour = int(b[2].encode('utf-8')) + 12
hour= b[2]
min = b[3]
OUTPUT = "%s-%s-%s %s:%s:00"% (year, month, day, hour, min)
print OUTPUT
对于这种正常的时间格式 http://www.cdnews.com.tw 2015-11-02 17:33:55
import re
INPUT="http://www.cdnews.com.tw 2015-11-02 17:33:55"
pattern = re.compile(r'[\d]+')
a = re.findall(pattern, INPUT)
year = a[0]
month = a[1]
day = a[2]
hour = a[3]
minute = a[4]
second = a[5]
OUTPUT = "%s-%s-%s %s:%s:%s" % (year,month,day,hour,minute,second)
print OUTPUT
对于这种时间格式 發表於: 星期三 十二月 14, 2016 6:45 pm
import re
INPUT = "發表於: 星期三 十二月 14, 2016 6:45 pm"
pattern = re.compile(r'[\d]+')
b = re.findall(pattern, INPUT)
a = INPUT.split(' ')
monthdict = {"一月": "","二月": "", "三月": "", "四月": "", "五月": "", "六月": "","七月": "", "八月": "", "九月": "", "十月": "", "十一月": "", "十二月": ""}
year = a[4]
month = monthdict[a[2]]
day = b[0]
if a[6] == 'pm':
hour = int(b[2].encode('utf-8')) + 12
elif a[6] == 'am':
h = int(b[2])
if h >= 10:
hour = h
elif h<10:
hour= ""+b[2]
min = b[3]
OUTPUT = "%s-%s-%s %s:%s:00"% (year, month, day, hour, min)
print OUTPUT
python解析时间格式脚本的更多相关文章
- python中时间格式
问题:通过MySQLdb查询datetime字段,然后通过浏览器显示出来,得到的格式是: 'Thu, 19 Feb 2009 16:00:07 GMT' (http呈现出来的格式) ...
- python:时间格式转化
1.获取秒级时间戳与毫秒级时间戳.微秒级时间戳 import time import datetime t = time.time() print (t) #原始时间数据 print (int(t)) ...
- python format 时间格式
trainData['survey_time'] = pd.to_datetime(trainData['survey_time'],format = '%Y/%m/%d %H:%M') trainD ...
- python 解析json格式
对于网页爬取结果为json格式的,可以直接使用python的json库解析,获取相应字段的值,比用正则匹配更简单规范. import json…… resp=requests.post(url,hea ...
- Python日志输出格式和时间格式
formatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s","%Y%b%d-%H:%M:% ...
- python解析VOC的xml文件并转成自己需要的txt格式
在进行神经网络训练的时候,自己标注的数据集往往会有数据量不够大以及代表性不强等问题,因此我们会采用开源数据集作为训练,开源数据集往往具有特定的格式,如果我们想将开源数据集为我们所用的话,就需要对其格式 ...
- python 爬虫时间数据-时间格式转换
1 import time,datetime 2 3 time_original = '17/Sep/2012:11:40:00' 4 time_format = datetime.datetime. ...
- python中将HTTP头部中的GMT时间转换成datetime时间格式
原文: https://blog.csdn.net/zoulonglong/article/details/80585716 需求背景:目前在做接口的自动化测试平台,由于接口用例执行后返回的结果中的时 ...
- Python 时间格式转换
Python time, datetime模块常用方法 1.使用time模块,获取当前时间戳~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~import timetime.time( ...
随机推荐
- 【dlbook】实践方法论
[性能度量] 使用什么误差度量? 目标性能大致为多少? [默认的基准模型] 首先尝试分段线性单元,ReLU以及扩展. SGD一般是合理的选择,选加入动量的版本,衰减方法不一. 批标准化在优化出现问题时 ...
- c# html内容处理类
using System; using System.Text; using System.Text.RegularExpressions; using System.Net; using Syste ...
- jQuery 滑动选项卡jQuery tabslet
Tabslet Yet another jQuery plugin for tabs, lightweight, easy to use and with some extra features ...
- Windows7下PHP 7.1搭建开发环境
引言: PHP天生就是用来解决互联网时代的Web语言问题的专业工具,本文将记录在windows上搭建PHP的过程以及其中碰到的问题. 配置版本信息 OS: Windows 7 PHP: 7.1.7-n ...
- Familia:百度NLP开源的中文主题模型应用工具包
参考:Familia的Github项目地址.百度NLP专栏介绍 Familia 开源项目包含文档主题推断工具.语义匹配计算工具以及基于工业级语料训练的三种主题模型:Latent Dirichlet A ...
- 【排序】归并排序,C++实现
原创文章,转载请注明出处! 博客文章索引地址 博客文章中代码的github地址 # 基本思想(分治法) 归并排序中, “归”代表递归的意思,即递归的将数组通过折半的方式分离为单个数组. “ ...
- slam学习
学习内容: 数学: 线性代数,概率论, 优化理论,离散数学, 李代数, 凸优化: 算法: 概率机器人, 机器人状态估计, 深度学习,非线性优化: 工程: c/c++ , python, ros, ...
- ExpressCache
ExpressCache 非联想.等品牌电脑使用的ExpressCache(带破解文件). (原始安装文件+patch+说明).注意,执行eccmd命令时,需要管理员权限.否则报错. http://a ...
- div横排放置对齐问题;block,inline,inline-block区别
1.左右两个div都设置为float:left,如果右边div没有设置宽度,右边div的宽度会根据div里的内容自动调整. 缺点:不易控制 2.只有左侧div设置为float:left,右侧div设置 ...
- 《DSP using MATLAB》示例Example 6.26
代码: % r = 0.9; theta = (pi/180)*[-55:5:-35, 35:5:55]'; p = r*exp(j*theta); a = poly(p); b = 1; % Dir ...