Solved

Python - how to convert UTC time string to local time

Posted on 2016-07-29
4
381 Views
Last Modified: 2016-08-01
I am getting this string from an API.
EX: 1469836074

If I go to this website and put the UTC string into it:
http://www.epochconverter.com/

Then I get human readable form:
GMT: Fri, 29 Jul 2016 23:47:54 GMT
Your time zone: 7/29/2016, 4:47:54 PM GMT-7:00 DST

What python library would take INPUT: 1469836074 and give output as something like:
GMT: Fri, 29 Jul 2016 23:47:54 GMT
Your time zone: 7/29/2016, 4:47:54 PM GMT-7:00 DST
or something like that.....

Thank you!
0
Comment
Question by:alexmac05
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 15

Accepted Solution

by:
WalkaboutTigger earned 500 total points
ID: 41735424
Well, you can either use

Import time

or

import calendar

The number in question is the number of seconds since 12:00:00 am January 1, 1970 UTC.  You would need to apply the local time offset to derive the time the number represents locally.

You can use
print time.strftime("%Z - %Y/%m/%d, %H:%M:%S", time.localtime(time.time()))

Open in new window

and replace time.time() with the epoch you wish to convert.

%Z is the local timezone as configured on the system.
0
 

Author Comment

by:alexmac05
ID: 41735851
Thank you!

This worked.
print time.strftime("%Z - %Y/%m/%d, %H:%M:%S", time.localtime(float(utcValue)))

where utcValue was a string = '1469836074'

this gave me the desired result of PDT - 2016/07/29, 16:47:54

Thank you thank you
0
 

Author Closing Comment

by:alexmac05
ID: 41735852
thank you
0
 
LVL 15

Expert Comment

by:WalkaboutTigger
ID: 41737652
Always happy to help!
0

Featured Post

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Variable is a place holder or reserved memory locations to store any value. Which means whenever we create a variable, indirectly we are reserving some space in the memory. The interpreter assigns or allocates some space in the memory based on the d…
This article will show the steps for installing Python on Ubuntu Operating System. I have created a virtual machine with Ubuntu Operating system 8.10 and this installing process also works with upgraded version of Ubuntu OS. For installing Py…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question