@franciscoareasareas/

local_utc_time

Python 2.7

convertions from local to utc and back

fork
loading
Files
  • main.py
  • test.json
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import time
import calendar

print 'utc to local'
utc_time = time.strptime("2018-12-13T10:32:00.000", "%Y-%m-%dT%H:%M:%S.%f")
print 'utc'
print utc_time
print 'local'
utc_seconds = calendar.timegm(utc_time)
local_time = time.localtime(utc_seconds)
print local_time

print '\nlocal to utc'

print 'local'
local_time = time.strptime("2018-12-13T09:32:00.000", "%Y-%m-%dT%H:%M:%S.%f")
print local_time

local_seconds = time.mktime(local_time)
utc_time = time.gmtime(local_seconds)
print 'utc'
print utc_time