如何获得在C原木适当的时间戳? [英] How to get appropriate timestamp in c for logs?
本文介绍了如何获得在C原木适当的时间戳?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建一个客户端 - 服务器应用程序。我想要做一些记录。
服务器是C.现在我打印消息到终端。所以,我可能就复制到sprintf和添加时间戳。
我怎样才能做到这一点时间戳?
它可能应该包括日期,小时,分钟,秒。
解决方案
的#include<&time.h中GT;
无效的时间戳()
{
time_t的LTIME; / *日历时间* /
LTIME =时间(NULL); / *获取当前CAL时间* /
的printf(%S,asctime(本地时间(安培; LTIME)));
}
在我的电脑,它只是打印
周三三月07 12点27分29秒2012
检查出的时间有关功能的整个范围在这里
<一href=\"http://pubs.opengroup.org/onlinepubs/7908799/xsh/time.h.html\">http://pubs.opengroup.org/onlinepubs/7908799/xsh/time.h.html
I'm creating a client-server application. I want to do some logging.
Server is in C. Now I'm print messages to the terminal. So I'll probably just copy that to sprintf and add timestamp. How can I do that timestamp? It should probably include date, hours, minutes, seconds.
解决方案
#include <time.h>
void timestamp()
{
time_t ltime; /* calendar time */
ltime=time(NULL); /* get current cal time */
printf("%s",asctime( localtime(<ime) ) );
}
On my PC, it just prints
Wed Mar 07 12:27:29 2012
Check out the whole range of time related functions here http://pubs.opengroup.org/onlinepubs/7908799/xsh/time.h.html
这篇关于如何获得在C原木适当的时间戳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文