初夏小談:判斷系統日期和時間(C語言)
阿新 • • 發佈:2018-11-25
計算系統當前日期和時間:
#define _CRT_SECURE_NO_WARNINGS 1 #include<stdio.h> #include<stdlib.h> #include<time.h> int main() { int array[] = { 0,1,2}; int num,count=0; struct tm *systime; time_t nowtime; time(&nowtime); systime = localtime(&nowtime); data: printf("如需說明請輸入數字0\n"); while (1) { printf("請輸入:\n"); scanf("%d", &num); count++; if (0 == num) { printf("輸入1現實當前系統日期,輸入2顯示當前系統時間,輸入其它任意字元,則退出查詢\n"); } else if (1 == num) { printf("當前系統日期:\n"); printf("%d-%d-%d\n", systime->tm_year + 1900, systime->tm_mon + 1, systime->tm_mday); } else if (2 == num) { printf("當前系統時間:\n"); printf("%d:%d:%d\n", systime->tm_hour, systime->tm_min, systime->tm_sec); } else { if (count < 2) { goto data; } printf("退出查詢\n"); break; } } system("pause"); return 0; }
珍&原始碼