utdf2gmns.util_lib.time_str_to_seconds

utdf2gmns.util_lib.time_str_to_seconds(time_str: str, to_unit: str = 'seconds', verbose: bool = True) int[source]

Convert a time string to seconds

Parameters:
  • time_str (str) – A time string, e.g., “12:00AM”, “9:00am”, “3:00pm”

  • to_unit (str) – The desired output unit. e.g. “seconds”, “minutes”, “hours”, “days”

  • verbose (bool) – Whether to print the conversion result. Defaults to True.

Example

>>> from pyufunc import time_str_to_seconds
>>> time_str_to_seconds("12:00AM")
0
>>> time_str_to_seconds("9:00am")
34200.0
>>> time_str_to_seconds("3:30pm")
55800.0
>>> time_str_to_seconds("3:30pm", to_unit="minutes")
930.0
Returns:

The time in the target unit.

Return type:

int