Is there any way to get the current time in microseconds resolution? specifically %y-%m-%dT%H:%M:%S:%f format?
Thanks!
Is there any way to get the current time in microseconds resolution? specifically %y-%m-%dT%H:%M:%S:%f format?
Thanks!
You can print a datetime in that format just by using strftime
:
>>> import datetime
>>> now = datetime.datetime.now()
>>> now
datetime.datetime(2019, 10, 17, 12, 45, 58, 294795)
>>> now.strftime("%Y-%m-%dT%H:%M:%S.%f")
'2019-10-17T12:45:58.294795'
Note that this is a separate issue to the resolution of your clock, it may be less than a microsecond. You can check that as well by using:
>>> str(datetime.time.resolution)
'0:00:00.000001'
As per the output, my Linux box (and Python 3.7 on my Win10 box) has a one-microsecond resolution.
You should import datetime and then, use strftime to format date and time.
Import datetime
Now= datetime.now()
Print(now.strftime("%Y-%M-%D %H:%M:%S.%f"))
Comlete the parenthesis with your desired format.