4

I receive a timestamp from a server like this 1512543958 & when i send back requests in headers i see a 13 digit GMT time stamp like this 1512544485819

By changing the time to local using the code below i get 2017-12-06 12:35:58

print(datetime.datetime.fromtimestamp(int("1512544474")).strftime('%Y-%m-%d %H:%M:%S')

& when i apply the code below i get 'Wed 06 Dec 2017 07:14:45 GMT'

time.strftime("%a %d %b %Y %H:%M:%S GMT", time.gmtime(1512544485819 / 1000.0))

So basically i need a python function that takes the 10 digit date timestamp as argument & returns 13 digit GMT date timestamp

example input 1512544474
expected output 1512544485819

Shekhar Samanta
  • 875
  • 2
  • 12
  • 25
  • 1
    _when i send back requests in headers i see a 13 digit GMT time stamp like this 1512544485819_, it means that you already have your expected output. – vishes_shell Dec 06 '17 at 07:32
  • i see that in chrome network elements , I need a python function that converts the 1512544474 to GMT time stamp 1512544485819 – Shekhar Samanta Dec 06 '17 at 07:34

1 Answers1

0

I am using python 2.7

import time
import datetime
import time as mod_time
from datetime import datetime
from datetime import datetime, timedelta
from datetime import date, timedelta  

today = datetime.now()
yesterday = datetime.now() - timedelta(days=1)
today_time = int((mod_time.mktime(today.timetuple())))
yesterday_time = int((mod_time.mktime(yesterday.timetuple())))
today_unixtime = (today_time*1000)
yesterday_unixtime = (yesterday_time*1000)
print("today timestamp =", today_unixtime)
print("yesterday timestamp =", yesterday_unixtime)

Output

('today timestamp =', 1579243097000)
('yesterday timestamp =', 1579156697000)

You can check the current time stamp from crome browser console.

new Date(1579243097000)

it will gives you a current date and time.

Atique Ahmed
  • 308
  • 4
  • 16