c++11 获得精确时间

#include <iostream>
#include <chrono>
#include <ctime>

#include <sys/timeb.h>
using namespace std;

int main()
{
	// using timeb.h -- deprecated
	struct timeb ft;
	ftime(&ft);	
	
	// using chrono
	auto tp = std::chrono::system_clock::now();
	auto now = std::chrono::system_clock::to_time_t(tp);		
	long long eee = std::chrono::system_clock::period::den / (1000* std::chrono::system_clock::period::num);
	long long fff = tp.time_since_epoch().count();
	int ms = (fff / eee) % 1000;


	printf("A1 %ld, %d\r\n", now, ms);
	
	printf("A2 %ld, %d\r\n", ft.time, ft.millitm);
	

	// change to readable string
	struct tm* gmtm = gmtime(&now);
// gmtm->tm_year+1900
// tmtm->tm_mon+1
	char* dt = asctime(gmtm);
	
	return 0;
}