码迷,mamicode.com
首页 > 其他好文 > 详细

时间戳转换为字符串

时间:2015-09-10 19:10:06      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:

#include <cctype>
#include <iostream>
using namespace std;


char* gettimestr(time_t itime, char* gettime, const char* format)
{
    struct tm ptm;
    
    localtime_r(&itime, &ptm);
    strftime(gettime, 1024, format, &ptm);
    return gettime;
}

int main()
{
    time_t tNow;
    tNow = time(NULL);
    int offset1 = 10;
    tNow = tNow - offset1 * 60;
    char cptimebegin[100];
    char cptimeend[100];
    gettimestr(tNow, cptimebegin, "%Y-%m-%d %H:%M:00");
    printf("After offset1, the begin time is %s\n", cptimebegin);

    int offset2 = 10;
    gettimestr(tNow - offset2 * 60, cptimeend, "%Y-%m-%d %H:%M:00");
    printf("After offset2, the begin time is %s\n", cptimeend);

    return 0;
}

 

时间戳转换为字符串

标签:

原文地址:http://www.cnblogs.com/foreverstars/p/4798625.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!