文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>time

time

时间:2010-04-12  来源:ubuntuer

 

#include <stdio.h>
#include <time.h>
#include <sys/time.h>

int main()
{
 struct timeval tv;
 struct tm* tm;
 time_t now;

 gettimeofday(&tv, NULL);
 now = time(NULL);

 tm = localtime(&now);
 printf("%d, %d\n", (int)tv.tv_sec, (int)now);
 
 printf("%d-%d-%d %d:%d:%d\n",1900+tm->tm_year, tm->tm_mon, tm->tm_mday,
                              tm->tm_hour, tm->tm_min, tm->tm_sec);
 return 0;
}

 

在不用设置时区的情况下gettimeofday和time是一样的...

localtime将time_t转换了struct tm结构...

对于结构体可以man gettimeofday   localtime

相关阅读 更多 +
排行榜 更多 +
一剑灭天

一剑灭天

角色扮演 下载
戮仙战纪

戮仙战纪

角色扮演 下载
头号海贼王手机版

头号海贼王手机版

棋牌卡牌 下载