Solved

Python - how to convert UTC time string to local time

Posted on 2016-07-29
4
128 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
  • 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
IronPython and Visual Studio 2013+ 2 98
Get IP addres information from field 3 54
Python Assistance 7 79
python sqlite question 11 46
A set of related code is known to be a Module, it helps us to organize our code logically which is much easier for us to understand and use it. Module is an object with arbitrarily named attributes which can be used in binding and referencing. …
Strings in Python are the set of characters that, once defined, cannot be changed by any other method like replace. Even if we use the replace method it still does not modify the original string that we use, but just copies the string and then modif…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…

813 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now