首页 > 其他 > 详细

时间戳转换为字符串

时间:2015-09-10 19:09:04      阅读:228      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!