C++
#include <iostream>
#include <time.h>
string getCurrentTimeStr(){
time_t t = time(NULL);
char ch[64] = {0};
char result[100] = {0};
struct timeval tv;
gettimeofday(&tv,NULL);
int ms = (tv.tv_sec*1000 + tv.tv_usec/1000)%1000;
strftime(ch, sizeof(ch) - 1, "%Y-%m-%d %H:%M:%S:", localtime(&t)); //年-月-日 时-分-秒
sprintf(result, "%s%d", ch, ms);
return string(result);
}
python
import time
import datetime
def get_time_stamp(time_stamp):
ct = time.time()
local_time = time.localtime(ct)
data_head = time.strftime("%Y-%m-%d %H:%M:%S", local_time)
data_secs = (ct - int(ct)) * 1000
time_stamp = "%s.%03d" % (data_head, data_secs)
return time_stamp