一、 通过time_t和tm
struct tm
{
int tm_sec; // seconds after the minute - [0, 60] including leap second
int tm_min; // minutes after the hour - [0, 59]
int tm_hour; // hours since midnight - [0, 23]
int tm_mday; // day of the month - [1, 31]
int tm_mon; // months since January - [0, 11]
int tm_year; // years since 1900
int tm_wday; // days since Sunday - [0, 6]
int tm_yday; // days since January 1 - [0, 365]
int tm_isdst; // daylight savings time flag
};
#include <iostream>
#include <time.h>
using namespace std;
int main()
{
// Unix标准时间戳(1970年1月1日0点0分0秒,GMT)经过了多少秒
time_t time_now = time(0);
cout << "1970年1月1日0点0分0秒 到目前经过秒数:" << time_now << endl;
tm* ltm = localtime(&time_now);
char location_now[20];
sprintf_s(location_now, "%d%02d%02d, %02d:%02d:%02d", 1900 + ltm-&