linux c 获取当前时间 毫秒级的 unix网络编程
2014-08-29 10:50
169 查看
#include <time.h>
#inlcude <sys/time.h>
char *
gf_time(void) /* get the time */
{
struct timeval tv;
static char str[30];
char *ptr;
if (gettimeofday(&tv, NULL) < 0)
err_sys("gettimeofday error");
ptr = ctime(&tv.tv_sec);
strcpy(str, &ptr[11]);
/* Fri Sep 13 00:00:00 1986\n\0 */
/* 0123456789012345678901234 5 */
snprintf(str+8, sizeof(str)-8, ".%06ld", tv.tv_usec);
return(str);
}
#inlcude <sys/time.h>
char *
gf_time(void) /* get the time */
{
struct timeval tv;
static char str[30];
char *ptr;
if (gettimeofday(&tv, NULL) < 0)
err_sys("gettimeofday error");
ptr = ctime(&tv.tv_sec);
strcpy(str, &ptr[11]);
/* Fri Sep 13 00:00:00 1986\n\0 */
/* 0123456789012345678901234 5 */
snprintf(str+8, sizeof(str)-8, ".%06ld", tv.tv_usec);
return(str);
}
相关文章推荐
- VC中如何获取当前时间(精度达到毫秒级)
- windows下用c++获取毫秒级的当前时间
- sql server获取当前时间到秒级和毫秒级的语句
- C++ 获取当前日期时间 毫秒级
- 根据当前日期获取本周起止时间
- Java,.NET中当前时间获取、格式化方法比较
- C中获取当前时间的函数
- java另一种获取当前系统的时间与日期
- 获取音乐文件的播放时间及当前进度
- Windows 驱动:获取系统当前时间,生成格式字符串
- 用Delphi获取当前系统时间
- JS之Date对象和获取系统当前时间(转)
- C# 如何获取当前日期和时间
- c语言获取系统当前时间
- java中获取当前系统时间,日期并格式化输出
- 根据当前时间获取学年和学期
- PHP获取系统当前时间
- 用Delphi获取当前系统时间
- JAVA 获取系统当前时间
- js,获取当前的时间