"Python" Uniform Conversion date format Dateutil.parser.parse

Source: Internet
Author: User

Background:

I have a lot of log data, every log has a date string, and I need to convert it to a DateTime format.

The problem is that there are a variety of string formats in these logs, with 2017-05-25t05:27:30.313292255z, 2016-07-01t00:00:00 and other formats I haven't seen yet.

At first I wrote a long list of if else to determine the format, but there was always something I missed.

Finally on the Internet a search, found dateutil.parser.parse. You can convert a string to a DateTime format without having to specify the format.

Import Datetimeimport dateutil.parserdef GetDateTime (s):    d = dateutil.parser.parse (s)    return D

Note: I tried the "19/may/2017:04:10:06 +0000" unexpectedly failed--! Maybe this function only knows the numbers and doesn't recognize the letters.

Forward ' https://www.cnblogs.com/dplearning/p/7388659.html

"Python" Uniform Conversion date format Dateutil.parser.parse

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.