Skip to content

Instantly share code, notes, and snippets.

@kehr
Created July 17, 2015 02:19
Show Gist options
  • Save kehr/5d15507a188f3938d59c to your computer and use it in GitHub Desktop.
Save kehr/5d15507a188f3938d59c to your computer and use it in GitHub Desktop.
把秒转化成hms格式。
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@File Name: time.py
@Author: kehr
@Mail: kehr.china@gmail.com
@Created Time: 日, 07/12/2015, 01时27分08秒
@Copyright: GPL 2.0
@Description:
"""
def cal(num):
num = int(num)
h = num / 3600
m = (num - h*3600) / 60
s = num - h*3600 - m*60
if 0 != h:
if 0 != m:
if 0 != s:
print "%sh%sm%ss" % (h,m,s)
else:
print "%sh%sm" % (h,m)
else:
if 0 != s:
print "%sh%sm%ss" % (h,m,s)
else:
print "%sh" % h
else:
if 0 != m:
if 0 != s:
print "%sm%ss" % (m,s)
else:
print "%sm" % m
else:
if 0 != s:
print "%ss" % s
else:
print "%ss" % s
if __name__ == "__main__":
import sys
args = sys.argv[1:]
for arg in args:
cal(arg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment