0

I have some problem to convert date in python.

For example you can see on the csv file, at the index 0 for the column "created_date", I have the value "1550740786000".

I would like the convert this date in a more "traditional form"

I tried to use the code below :


Input:

time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(int(pd_testData_filtered["created_at"].iloc[0])))

Output:

51109-10-14 02:13:20

This tweet has been published at 14:29 20/02/2019

Could someone help me?

Best regards.

CSV file

Tamara Koliada
  • 1,200
  • 2
  • 14
  • 31

1 Answers1

1

This looks like a Posix timestamp but expressed in milliseconds. So strip the last 3 digits:

>>> timestamp = 1550740786000
>>> datetime.datetime.fromtimestamp(timestamp / 1000)
datetime.datetime(2019, 2, 21, 10, 19, 46)

This isn't exactly the publication time you report, but some hours earlier, and it is plausibly close enough to be worth investigating: the original timestamp of a retweet, maybe?

BoarGules
  • 16,440
  • 2
  • 27
  • 44
  • I suspect the couple hours difference is due to a timezone difference. – Nathan Feb 21 '19 at 13:35
  • @Nathan Timezone differences are rarely more than 13 hours, and even ignoring the hour offset, that wouldn't explain the 10 minute difference. – BoarGules Feb 21 '19 at 13:37
  • It is basically a tweet from Theresa May. I am actually in Moscow, maybe it could explain the difference? – Stefan Hanssen Feb 21 '19 at 13:43
  • No, Moscow time is UTC+3, so 10:19 on 21 February in London was 13:19 in Moscow, and 14:29 in on 20 February in London was 17:29 in Moscow. https://www.timeanddate.com/worldclock/converter.html?iso=20190221T101900&p1=136&p2=166 – BoarGules Feb 21 '19 at 13:47
  • @BoarGules Thank you a lot for your help :) – Stefan Hanssen Feb 21 '19 at 14:46