[Python] Convert time string expressed as <number>[m|h|d|s|w] to seconds

Discussão em 'Python' iniciado por Stack, Julho 24, 2025.

  1. Stack

    Stack Membro Participativo

    How can I convert a string representing time in the format of <number>[m|h|d|s|w] (m= minutes, h=hours, d=days, s=seconds w=week) to number of seconds? E.g.:

    def convert_to_seconds(timeduration):
    ...

    convert_to_seconds("1h")
    -> 3600

    convert_to_seconds("1d")
    -> 86400

    Continue reading...

Compartilhe esta Página