Linux C++ 时间格式化

来源:互联网 发布:阿里云 自己安装系统 编辑:程序博客网 时间:2024/06/05 20:43
/*************************************************************************
    > File Name: time.cpp
    > Author: chenhui
    > Mail: *********
    > Created Time: 2016年03月10日 11:20:58
 ************************************************************************/
#include <iostream>
#include <ctime>
using namespace std;


int main()
{
        time_t now_time;
        char buf[128] = {0};
        tm * local;

        now_time=time(NULL);
        cout<<now_time<<endl;
        cout<<now_time-100<<endl;

        local = localtime(&now_time);
        strftime(buf, 128,"%Y-%m-%d %H:%M:%S", local);
        cout<<"time format:"<<buf<<endl;
        return 0;
}
0 0
原创粉丝点击