Per ottenere timestamp in JavaScript usiamoJavaScript timestamp a Python conversione datetime
var ts = new Date().getTime()
Qual è il modo corretto di convertirlo in un Python datetime
finora ho utilizzare il seguente codice
>>> jsts = 1335205804950
>>> dt = datetime.datetime.fromtimestamp(jsts/1000)
>>> dt
datetime.datetime(2012, 4, 24, 0, 30, 4)
I divide il timestamp di 1000 perché ottengo un errore come
ValueError Traceback (most recent call last)
1 d = datetime.datetime.fromtimestamp(a)
ValueError: year is out of range
Sultan.
Per fortuna, questo non è necessario in Python 3. – delnan
Grazie a @ F.J :). – sultan
@delnan Ho lo stesso problema in python3: 'datetime.fromtimestamp (1485373592240)' fallisce a meno che diviso per '1000' – jjj