summaryrefslogtreecommitdiffstats
path: root/build/unix-time-to-fmt.py
blob: 72ece26989a22b671fe44ac5ca5a204fab310f1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python
"""
Usage:

  unix-time-to-fmt.py 1234567 [%Y-%m-%d[...]]

Convert unix timestamp to a string of the given format in UTC, according to
  https://docs.python.org/2/library/time.html
Default is '%Y-%b-%d' --> 2016-Jan-01
"""

import sys, time

if len(sys.argv) == 1:
    print("unknown")
    exit(0)

fmt = '%Y-%b-%d'
if len(sys.argv) > 2:
  fmt = sys.argv[2]

print(time.strftime(fmt, time.gmtime(float(sys.argv[1]))))