1

Hi I have a log file with epoch date time in it as follows:

...
1668516788.901393
1668516788.902532
1668516788.911157
1668516788.921403
1668516788.922577
...

I need to convert this into a datetime format as follows:

15 Nov 2022, 18:25:31.256

I have used the following code:

mytime = time.asctime(time.localtime(float(mytime)))

to get an output of Tue Nov 15 12:53:08 2022 but this is missing the millisecond portion of time.

Is there a way to retain the millisecond part of the time?

Fasih
  • 11
  • 2

1 Answers1

1

You have to use datetime module instead of asctime (datetime can convert into milliseconds too) e.g.:

mytime = datetime.datetime.fromtimestamp(mytime)
mytime_as_string = mytime.strftime("%d %b %Y, %H:%M:%S.%f")