0

I'm converting a parameter of seconds in the current time in the format hh:mm:ss, but I need to convert in the format hh:mm:ss.ms but I'm not getting it.I'm using the strftime

function and I can convert to hh:mm:ss format.

   f_datetime = '%H:%M:%S.%f'
 
   time_cap = time.strftime(f_datetime, time.localtime(pkt_time_cap.tv_sec))

   print(time_cap)
Result: 06:08:04.%f

Ps1: pkt_time_cap.tv_sec is my param for seconds

Can you help me ?

Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
D-LA
  • 17
  • 4

1 Answers1

0

on this post i think i found a solution who is:

from datetime import datetime
time_cap=datetime.now().strftime("%H:%M:%S.%f")
print(time_cap)
El Santo
  • 3
  • 7
  • was using the time library as it allows converting seconds to current time. Is it possible with datetime? – D-LA Jun 20 '22 at 17:31
  • i found this [link](https://stackoverflow.com/questions/44823073/convert-datetime-time-to-seconds) who show us this: `t = datetime.now().time() seconds = (t.hour * 60 + t.minute) * 60 + t.second print(seconds)` – El Santo Jun 21 '22 at 07:57