static gint64 get_nsec(){
gint64 val = 0;
struct timespec ts = {0};
clock_gettime(CLOCK_REALTIME, &ts);
val = ts.tv_sec * 1000000000 + ts.tv_nsec;
return val;
}
static gint64 get_usec(){
gint64 val = 0;
struct timeval tv;
gettimeofday(&tv, NULL);
val = tv.tv_sec * 1000000 + tv.tv_usec;
return val;
}
static gint64 get_msec(){
gint64 val = 0;
struct timeval tv;
gettimeofday(&tv, NULL);
val = tv.tv_sec * 1000 + tv.tv_usec/1000;
return val;
}
获取的常数时间转为localtime
#!/usr/bin/env python
#coding=utf-8
import os
import sys
import time
import traceback
if __name__ == "__main__":
lines = [];
if len(sys.argv) >= 2:
if os.path.exists(sys.argv[1]):
fp = open(sys.argv[1], "r");
lines = fp.readlines();
fp.close();
else:
longtime = 0;
try:
longtime = int(sys.argv[1]);
except:
traceback.print_exc();
exit(0)
if longtime != 0:
lines.append(sys.argv[1]);
else:
print "File:%s NOT exist!" % (sys.argv[1])
exit(0);
else:
lines = sys.stdin.readlines();
for line in lines:
longtime = 0;
try:
longtime = int(line);
except:
traceback.print_exc();
exit(0);
tm0 = time.localtime(longtime);
strtime = time.strftime('%Y%m%d %02H:%02M:%02S', tm0).strip();
print "##: %d ==> %s" % (longtime, strtime)