GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — learn-cpp/basic/cpp-time/main.cpp at master · zing-dev/learn-cpp Expand file tree/ Copy pathmain.cppMore file actions 58 lines (50 loc) · 1.24 KB / Copy pathmain.cppFile metadata and controls58 lines (50 loc) · 1.24 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 // // Created by zhangrongxiang on 2017/10/21 22:58 // File main // #include <iostream> #include <ctime> #include <unistd.h> 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; } |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |