How to convert a UTC time to local time in Python

Source: Internet
Author: User

Demand:

Converts 20141126010101 format UTC time to local time.

Searching the internet for a long time did not find the perfect solution. Some refer to third-party libraries, which requires the installation of third-party software on the Web. This is a must. Because the real environment does not necessarily allow you to use the root user to install the Python module. Finally found a perfect solution without external modules, put it here to share with you.

1 #!/usr/bin/python2 3 ImportOs,sys,datetime,time4  fromDatetimeImportdatetime5 ImportCalendar6 7s ='20141125010101'8 PrintTime.strftime ('%y%m%d%h%m%s', Time.localtime (Calendar.timegm (Time.strptime (s),'%y%m%d%h%m%s'))))

Results: 20141125090101
Obviously added our time zone for 8 hours.

How to convert a UTC time to local time in Python

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.