0

How can I change the time without turning it into a string object (which dt.strftime does)? Like if I want to turn (default time format and time object)%H:%M:%S into %I:%M:%S %p or turn %H:%M:99(Default under time column in csv file data) into %H:%M:00?

Strftime helps resolve the problem, but it also results in data conversion (from datetime format to a string format) as per my instructor.

Jitin
  • 1
  • 1
  • 1
    `%H:%M:%S` is a string representation format of the time, so your question doesn't make much sense to me. Do you have a string with this format that you want to change? Do you have a `time` object that you want to show in some format? – Yevhen Kuzmovych Jun 19 '23 at 10:39
  • I am only saying what my instructor said. He said the original data under Time column is not a string, but time object. So if I use strftime to change (59 seconds to 00seconds or change the format of time from 24 hour clock to 12 hour clock with am/pm), the data type gets altered . So if I can not use strftime, what else can I use to get the desired change? – Jitin Jun 19 '23 at 10:53

1 Answers1

0

Changing 59 seconds to 00 seconds is changing the value of seconds, for this use .replace(seconds=0).

Changing the 24-hour clock to a 12-hour clock with am/pm is not a time object property, it's only a display format (when converting time to a string).

Yevhen Kuzmovych
  • 10,940
  • 7
  • 28
  • 48