/*
* =====================================================================================
*
* Filename: time.c
*
* Description:
*
* Version: 1.0
* Created: 2011年07月19日 10时38分20秒
* Revision: none
* Compiler: gcc
*
* Author: sunsea (zsx), sunsea1026@gmail.com
* Company:
*
* =====================================================================================
*/
#include <stdio.h>
#include <string.h>
#include <time.h>
int main(int argc, char* argv[])
{
time_t tv;
struct tm *lc_time;
char time_str[128];
/* 获取时间,以格林尼治时间(GMT)为标准,
* 从1970年1月1日00:00:00到现在的此时此刻所经过的秒数。*/
tv = time(NULL);
/* 把从1970-1-1零点零分到当前时间系统所偏移的秒数时间转换为日历时间。 */
lc_time = localtime(&tv);
/* asctime(),转换日期和时间为ASCII码 */
memset(time_str, 0, sizeof(time_str));
strcpy(time_str, asctime(lc_time));
printf("%s", time_str);
return 0;
}
linux下时间编程
最新推荐文章于 2023-06-11 12:46:51 发布