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爆的地方,希望大家可以给 ...
随机推荐
- Linux 2.6内核Makefile浅析【转】
转自:http://blog.csdn.net/tommy_wxie/article/details/7280463 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[-] 概述 ...
- 让button居中显示的的标签
<center> <input type="button" class="buttoncls" style="width:80px& ...
- 编译opencv2.4.11时出现错误:error: ‘NppiGraphcutState’ has not been declared
安装cuda之后再安装opencv时出现错误: /data/opencv-2.4.11/modules/gpu/src/graphcuts.cpp:120:54: error: ‘NppiGraphc ...
- 使用 .NET Core 的日志记录
如何使用 Microsoft.Extensions.Logging public static void Main(string[] args = null) { ILoggerFactory ...
- ie_placeholder最佳兼容方案
https://gitee.com/hustcc/placeholder.js巧妙的使用了canvas.toDataURL(),动态生成了一个背景图,可以作为兼容IE9-的placeholder方案. ...
- python Tk()生成的桌面的具体设置方法
rom tkinter import * root = Tk() root['height'] = 300 #设置高 root['width'] = 500 #设置宽 root.title('魔方小站 ...
- xampp 通过pear安装PHP_UML
1.在环境变量中添加D:\xampp\php // 如果前面已经有其他环境变量了,那么要用分号;跟前面的隔开 2.ctrl+R , cmd , pear install PHP_UML 3.如果提 ...
- 基于tinkphp3.2获取openid
<?php namespace Home\Controller; use Think\Controller; /** * 基础 */ class BaseController extends C ...
- HDU 6322.Problem D. Euler Function -欧拉函数水题(假的数论题 ̄▽ ̄) (2018 Multi-University Training Contest 3 1004)
6322.Problem D. Euler Function 题意就是找欧拉函数为合数的第n个数是什么. 欧拉函数从1到50打个表,发现规律,然后勇敢的水一下就过了. 官方题解: 代码: //1004 ...
- POJ 1321 棋盘问题【DFS/回溯/放与不放/类似n皇后】
棋盘问题 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 62164 Accepted: 29754 Description 在一 ...