码迷,mamicode.com
首页 > 编程语言 > 详细

Python 调整日期格式

时间:2017-06-28 10:03:02      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:ros   sof   microsoft   find   mon   logs   int   nbsp   日期格式   

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 调整日期格式

标签:ros   sof   microsoft   find   mon   logs   int   nbsp   日期格式   

原文地址:http://www.cnblogs.com/zhangtianyuan/p/7088335.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!