Chinaunix首页 | 论坛 | 博客
  • 博客访问: 277416
  • 博文数量: 72
  • 博客积分: 2387
  • 博客等级: 大尉
  • 技术积分: 720
  • 用 户 组: 普通用户
  • 注册时间: 2010-08-26 10:54
文章分类

全部博文(72)

文章存档

2012年(1)

2011年(1)

2010年(70)

分类: C/C++

2010-11-16 16:55:17

time_t实际是一个整型,单位为秒, 当你调用time()时返回的就是从1970,1,1,0:0:以来的秒数。
tm是一个结构,
  struct tm {
  int tm_sec; /* seconds */
  int tm_min; /* minutes */
  int tm_hour; /* hours */
  int tm_mday; /* day of the month */
  int tm_mon; /* month */
  int tm_year; /* year */
  int tm_wday; /* day of the week */
  int tm_yday; /* day in the year */
  int tm_isdst; /* daylight saving time */
  }

你可以通过调用一些接口把time_t的秒数转化为tm更为直观的结构/

string和time_t类型转换

time_t startTime;
struct tm sourcedate;
  
    memset(&sourcedate,0,sizeof(sourcedate));
    sourcedate.tm_sec = atoi(stime.substr(12,2).c_str());
    sourcedate.tm_min = atoi(stime.substr(10,2).c_str());;
    sourcedate.tm_hour = atoi(stime.substr(8,2).c_str());
    sourcedate.tm_mday = atoi(stime.substr(6,2).c_str());
    sourcedate.tm_mon = atoi(stime.substr(4,2).c_str()) - 1;
    sourcedate.tm_year = atoi(stime.substr(0,4).c_str()) - 1900;
    startTime = mktime(&sourcedate);
阅读(3841) | 评论(0) | 转发(0) |
0

上一篇:memset

下一篇:printf 字符串

给主人留下些什么吧!~~