0

I need your help. I have parsed a web site, and I have harvested this:

2018-08-18T23:31:00

I searched, but couldn't find how to change datetime to timestamp

Example of my desired result :

1535414693077
SherylHohman
  • 16,580
  • 17
  • 88
  • 94
sapiron
  • 93
  • 2
  • 7
  • Convert to `datetime` (e.g. `datetime.fromisoformat(date_str)` py3.7 or use `strptime(date_str, '%Y-%m-%dT%H:%M:%S')`) and call `datetime.timestamp()` – AChampion Aug 29 '18 at 00:18
  • Ty its work my_string = "2018-08-18T23:31:00" a = datetime.strptime(my_string, '%Y-%m-%dT%H:%M:%S') b = datetime.timestamp(a) – sapiron Aug 29 '18 at 00:43

1 Answers1

0

The previous answer is incorrect as there is no '%s' formatter in datetime, even though it works, sometimes. See this answer for how wrong it is to use '%s'.

from datetime import datetime
import pytz
pytz.utc.localize(datetime.strptime('2018-08-18T23:31:00', '%Y-%m-%dT%H:%M:%S')).timestamp()

Output (float): 1534635060.0

Moobie
  • 1,445
  • 14
  • 21