我需要从计时器中获取毫秒数。
// get timer part
time_t timer = time(NULL);
struct tm now = *localtime( &timer );
char timestamp[256];
// format date time
strftime(timestamp, sizeof(timestamp), "%Y-%m-%d_%H.%M.%S", &now);
我想在C#中获得这样的结果:
DateTime.Now.ToString("yyyy-MM-dd_HH.mm.ss.ff")
我尝试使用%f或%F但在C++中无法使用,如何从tm获取毫秒的%f?
time()
返回自纪元以来经过的整数秒数。因此,显然您不能通过使用它获得亚秒级精度。请改用gettimeofday()
。 - Hristo Iliev