python时间整形转标准格式的示例分享

代码如下:

import osimport sysimport pickleimport stringimport reimport timefrom datetime import datefrom csv_timestamp_datetime import * ip_region_list = pickle.load(open(‘ip_region_list.pickle’,’r’))ip_region_list.sort(key=lambda x: x[0])list_len = len(ip_region_list)def find(key): begin = 0 end = list_len – 1 while(begin = key: end = middle – 1 else: begin = middle + 1 def ip2region(): of = open(sys.argv[1], ‘r’) nf = open(sys.argv[2], ‘w’) for line in of: items = line.strip().split(‘,’) try: x = time.localtime(long(items[0])) ymdhms = time.strftime(‘%y-%m-%d %h:%m:%s’,x) nf.write(‘,’.join( [ ymdhms , items[1] , long2ip(long(items[2])) ]) + ‘\n’) except exception as e: print e print lineif (__name__ == ‘__main__’): ip2region()