获得毫秒级的时间 [英] Get millisecond part of time
本文介绍了获得毫秒级的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从计时器中获取毫秒数
I need to get milliseconds from the timer
// 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#中获得这样的代码:
I want to get like this in C#:
DateTime.Now.ToString("yyyy-MM-dd_HH.mm.ss.ff")
我尝试使用%f或%F,但它确实适用于C ++。如何从tm中获取%f毫秒?
I tried using %f or %F but it does work with C++. how can I get %f for milliseconds from tm?
推荐答案
有函数getimeofday()。返回以毫秒为单位的时间
在此处检查: http://souptonuts.sourceforge.net/代码/gettimeofday.c.html
there is the function getimeofday(). returns time in ms check here: http://souptonuts.sourceforge.net/code/gettimeofday.c.html
这篇关于获得毫秒级的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文