#!/usr/bin/env python2 import time import sys import getopt def usage(): '''Function to print out the usage of the script ''' print "Script to validate convert from timestamps to human times " print "Usage:" print "epochToHuman.py [-h] [-t] ]" print "" print "Where:" print " is the timestamp to be converted." print "" print "Options:" print "-h, --help Prints this help." print "-t, --t Take the timestamp to convert." print "" def parseOptions(): '''Function to read in the command line options ''' eventtime = None try: opts, args = getopt.getopt(sys.argv[1:], "h:t:", ["help", "timestamp="]) except getopt.GetoptError, err: print str(err) usage() sys.exit(2) timeStamp = -1 verboseFlag = False for opt, val in opts: if (opt in ("-h", "--help")): usage() sys.exit() if (opt in ("-t", "--timestamp")): timeStamp = int(val) # Return the event time and the subdetectors selected return (timeStamp) #def convertTime(timeStamp): def convertTime(): '''Small function to convert time-stamps''' # Read in the command-line options timeStamp = parseOptions() # Convert to human readable format (converted to localtime) hum1 = time.ctime(timeStamp) print "human readable: ", hum1 # Convert to formatted human readable time (formats in python-time-info.pdf) ltim1 = time.localtime(timeStamp) # localtime gtim1 = time.gmtime(timeStamp) # gmt time t1 = time.strftime("%d-%m-%y::%H:%M:%S",ltim1) t2 = time.strftime("%d-%m-%y::%H:%M:%S",gtim1) print "localtime string: ", t1 print "gmtime string: ", t2 # Convert from formatted time string to epoch etim1 = time.strptime(t1, "%d-%m-%y::%H:%M:%S") epoch = time.mktime(etim1) print "epoch time seconds: ", epoch if __name__ == '__main__': #timeStamp = int(sys.argv[1]) #convertTime(timeStamp) convertTime()