Convert Seconds to Timestamp (Python)

Convert a count in seconds to hours and minutes (seconds can trivially be added). For example 3600 to 1h

Details

Snippet

def secondsToTime(s):
    ''' Convert a count in seconds to hours and minutes

    Args:

    s - count in seconds
    '''

    if not s:
        return "0h 0m"

    mins, secs = divmod(int(s),60)
    hours, mins = divmod(mins,60)

    return "%dh %02dm" % (hours,mins)

Usage Example

>>> secondsToTime(6300)
'1h 45m'