Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert current datetime into 13 digits Unix timestamp? [duplicate]

I want to convert current datetime into Unix time stamp

My Code

import time
import datetime

d = datetime.datetime.now()
unixtime = time.mktime(d.timetuple())

print(unixtime)

My output:

1577098747.0

Expected Output:

1577098747123.0

Above code gives me timestamp upto 10 digits but I want it to be accurate till 13 digits.

Note: I don't want to convert it manually multiplying by 10**3 I want to capture accurate milliseconds.

like image 949
Sociopath Avatar asked Dec 23 '19 11:12

Sociopath


1 Answers

do it like this

import time
import datetime

d = datetime.datetime.now()
unixtime = datetime.datetime.timestamp(d)*1000

print(unixtime)

or you just use time.time()

like image 54
man zet Avatar answered Oct 16 '22 11:10

man zet