//
// Created by zhangrongxiang on 2017/10/21 22:58
// File main
//
#include
#include
#include
using namespace std;
void one();
void two();
void three();
int main() {
one();
two();
int i = 0;
while (i++ < 10) {
sleep(1);
three();
}
}
void three() {
time_t rawtime;
struct tm *info;
char buffer[80];
time(&rawtime);
info = localtime(&rawtime);
strftime(buffer, 80, "%x - %I:%M:%S %p", info);
// printf("æ ¼å¼åçæ¥æ & æ¶é´ : |%s|\n", buffer );
cout << buffer << endl;
}
void two() {
time_t now = time(nullptr);
tm *pTm = localtime(&now);
cout << "year : " << pTm->tm_year + 1900 << endl;
cout << "month : " << pTm->tm_mon + 1 << endl;
cout << "tm_mday : " << pTm->tm_mday << endl;
cout << "tm_wday : " << pTm->tm_wday << endl;
cout << "tm_yday : " << pTm->tm_yday << endl;
}
void one() {
// åºäºå½åç³»ç»çå½åæ¥æ/æ¶é´
time_t now = time(nullptr);
// æ now 转æ¢ä¸ºå符串形å¼
char *dt = ctime(&now);
cout << "æ¬å°æ¥æåæ¶é´ï¼" << dt << endl;
// æ now 转æ¢ä¸º tm ç»æ
tm *gmtm = gmtime(&now);
dt = asctime(gmtm);
cout << "UTC æ¥æåæ¶é´ï¼" << dt << endl;
}