Python 自用代码(调整日期格式)
2017年6月28日 to 2017-06-28
2017年10月27日 to 2017-10-27
2017年12月1日 to 2017-12-01
2017年7月1日 to 2017-07-01
#coding=utf-8 def func(string):
year = string.find(u'年')
month = string.find(u'月')
day = string.find(u'日')
if month-year==2:
string = string.replace(u"年",u"年0")
if day-month==2:
string = string.replace(u"月",u"月0")
return string.replace(u"日","").replace(u"月","-").replace(u"年","-") if __name__ == '__main__':
l1 = u"2017年6月28日"
l2 = u"2017年10月27日"
l3 = u"2017年12月1日"
l4 = u"2017年7月1日"
print func(l1)
print func(l2)
print func(l3)
print func(l4)
Python 自用代码(调整日期格式)的更多相关文章
- Python 自用代码(某方标准类网页源代码清洗)
用于mongodb中“标准”数据的清洗,数据为网页源代码,须从中提取: 标准名称,标准外文名称,标准编号,发布单位,发布日期,状态,实施日期,开本页数,采用关系,中图分类号,中国标准分类号,国际标准分 ...
- 给Nginx配置日志格式和调整日期格式
效果对比 官方默认日志格式 # 官方默认日志格式 log_format main '$server_name $remote_addr - $remote_user [$time_local] &qu ...
- 【python】统一转换日期格式dateutil.parser.parse
背景: 我有很多很多的日志数据,每个日志里面都有日期字符串,我需要将其转换为datetime格式. 问题是,这些日志里的字符串格式五花八门,有2017-05-25T05:27:30.313292255 ...
- Python编程举例-自定义日期格式
#自定义格式 x = '{0}{0}{0}'.format('dog') print(x) class Date: def __init__(self,year, mon,day): self.yea ...
- EXCEL 调整日期格式
https://jingyan.baidu.com/article/647f0115ea31b67f2048a85a.html 先中数据(不带标题),点击菜单-数据-分列. 前2步不要做任何更改直接点 ...
- Python 自用代码(知网会议论文网页源代码清洗)
#coding=utf-8 from pymongo import MongoClient from lxml import etree import requests jigou = u" ...
- Python 自用代码(递归清洗采标情况)
将‘ISO 3408-1-2006,MOD ISO 3408-2-1991,MOD ISO 3408-3-2006,MOD’类似格式字符串存为: [{'code': 'ISO 3408-1-200 ...
- Python 自用代码(拆分txt文件)
现有一个28G的txt文件,里面每一行是一个分词过的专利全文文档,一共370多万行.我需要把它按每五万行为单位做成一个json文件,格式大致如下: [{"id":"100 ...
- Python 自用代码(scrapy多级页面(三级页面)爬虫)
2017-03-28 入职接到的第一个小任务,scrapy多级页面爬虫,从来没写过爬虫,也没学过scrapy,甚至连xpath都没用过,最后用了将近一周才搞定.肯定有很多low爆的地方,希望大家可以给 ...
随机推荐
- python 学习笔记 aiohttp
asyncio可以实现单进程并发IO操作,如果仅用在客户端,发挥的威力并不大,如果把asyncio用在服务器端,由于http链接就是IO操作, 因此可以用单线程+coroutine实现多客户的高并发支 ...
- CSS边框属性
边框 圆角 border-radius border-top-left-radius border-top-right-radius border-bottom-left-radlius border ...
- shipyard, swarm看到你,我才睡觉:)
windows下用boot2docker有点不爽,就是网卡识别不好. 还是用纯的virtualbox建centos7虚拟机来搞, 一下就OK. 但记得,要用Iptables来弄墙,去掉firewall ...
- AC日记——曼哈顿交易 洛谷 P3730
曼哈顿交易 思路: 都是套路: 代码: #include <cmath> #include <cstdio> #include <cstring> #include ...
- 计蒜客 30996.Lpl and Energy-saving Lamps-线段树(区间满足条件最靠左的值) (ACM-ICPC 2018 南京赛区网络预赛 G)
G. Lpl and Energy-saving Lamps 42.07% 1000ms 65536K During tea-drinking, princess, amongst other t ...
- HDU 4355.Party All the Time-三分
Party All the Time Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- UVA Rails(stl-stack)
具体思路是从B方向的序列 倒推 栈C 的入栈出栈顺序, 以B方向的5,4,3,2,1为例子:从一个数字5开始,要想从栈C拿到5号车厢,5号车厢得入栈C,且5号车厢处于栈顶位置,为了保证5号车 厢在 ...
- CodeForces 32C Flea
题目链接:http://codeforces.com/problemset/problem/32/C 本文链接:http://www.cnblogs.com/Ash-ly/p/5513436.html ...
- hadoop学习一:hadoop安装(hadoop2.4.1,ubuntu14.04)
1.创建用户 adduser hduser 修改hduser用户权限: sudo vim /ect/sudoers ,在文件中增加 hduser ALL=(ALL:ALL) ALL .
- 训练指南 UVALive - 3713 (2-SAT)
layout: post title: 训练指南 UVALive - 3713 (2-SAT) author: "luowentaoaa" catalog: true mathja ...