Long-term viewing of monitoring data, the timestamp format of the monitoring data is the standard UNIX timestamp, to see the effort, so he wrote a small program
The code is as follows
#!/bin/env python#coding:utf8#unix timestamp Conversion Import sys, time, os, redef com_judge (): ' @ to determine if the executing program is followed by parameters ' ' com_count = len (SYS.ARGV) if com_count == 2: content = sys.argv[1] return content else: output = "Usage->> \n\tpython %s 1418239565\n\tpython %s timestamp_filename " print output % (Sys.argv[0],sys.argv[0]) exit (1) def dispose (content): if Os.path.isfile (content): with open (content) as Timefile: line_start=1 for read in timefile: read = read.strip () #判断文件中的时间戳格式是否正确 if re.match (r "\d{10,12}", Read): timestamp =int (Read) #利用python time modules for timestamp conversion timeArray = Time.localtime (TimeStamp) otherstyletime = time.strftime ("%Y-%m-%d %H:%M:%S", Timearray) print read + " : " + otherstyletime line_ start += 1 else: print&nbsP; " line " + repr (line_start) + " ERROR: " + read exit (1) else: input_time = content # Determine if the input timestamp format is correct if re.match (r "\d{10,12}", input_time): timestamp =int (input_time) timearray = time.localtime ( TimeStamp) otherStyleTime = Time.strftime ("%y-%m-%d %h:%m:%s", timearray) print input_time + " : " + otherstyletime else : print "UNIX TimeStamp error : " + input_time exit (1) def main (): user_input = com_judge () dispose (user_input) if __name__ == ' __main__ ': main ()
execution, which can be executed directly with the timestamp
You can also put a lump of time stamp into a file
OK, done, I was to put this program directly under the/usr/bin/, gave permission to use more convenient
A small program of UNIX timestamp conversions