#include <time.h>  
#include <stdio.h>
#include <iostream>
#include <string>
#include <string.h>
#include <sstream>
using namespace std;

int main()  
{  
    time_t now = time(0);  
    cout << now << endl;

    char* date = ctime(&now); //时间转为字符串
    cout << date ;

    struct tm* p = localtime(&now); /*转换为struct tm结构的UTC时间*/  
    printf("%d/%d/%d \n", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday);  

    //int 转为 string
    stringstream stream;
    stream << 1900 + p->tm_year;
    string year = stream.str();
    cout << year <<endl;

    return 0;  
}

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-09
  • 2022-01-10
  • 2022-12-23
  • 2022-12-23
  • 2021-06-11
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2022-02-13
  • 2021-10-16
相关资源
相似解决方案