免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: aychxm
打印 上一主题 下一主题

[函数] 求一个时间个是转换函数 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2013-08-08 12:49 |只看该作者
:wink:新手求助!!!

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
12 [报告]
发表于 2013-08-09 09:41 |只看该作者
我们在用的代码,应该是你要的

  1. #include <time.h>
  2. #include <sys/time.h>

  3. /**
  4. * get the local date or time in specified time zone for the specified UTC timestamp.
  5. * you can pass NULL for pointer-typed parameters.
  6. * return 0 on sucess, return -1 if error occured.
  7. * @year will be the A.D number, @month will be 1~12, @mday will be 1~31
  8. */
  9. int util_time(time_t timestamp, int32_t* year, int32_t* month, int32_t* mday, int32_t* hour, int32_t* minute, int32_t* second, int32_t zone)
  10. {
  11.         timestamp += zone*3600;
  12.         struct tm tmresult;
  13.         if(NULL==gmtime_r(&timestamp, &tmresult))
  14.                 return -1;
  15.         if(NULL!=year)
  16.                 *year = tmresult.tm_year + 1900;
  17.         if(NULL!=month)
  18.                 *month = tmresult.tm_mon + 1;
  19.         if(NULL!=mday)
  20.                 *mday = tmresult.tm_mday;
  21.         if(NULL!=hour)
  22.                 *hour = tmresult.tm_hour;
  23.         if(NULL!=minute)
  24.                 *minute = tmresult.tm_min;
  25.         if(NULL!=second)
  26.                 *second = tmresult.tm_sec;
  27.         return 0;
  28. }
复制代码
这样调用
  1. util_time(stamp, &year, &mon, &mday, &hour, &minute, &second, 8);
复制代码
然后自己sprintf一下就可以了

论坛徽章:
0
13 [报告]
发表于 2013-08-23 18:32 |只看该作者
http://www.cppblog.com/zdhsoft/archive/2013/06/27/201343.html 这里是我开发服务器常用的时间函数,看看能不能对你有用。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP