#include<time.h>
          #include<iostream>

          using namespace std;

          int main()
          {
          time_t timeval;
          timeval=time(NULL);
          cout<<"Time as local time is "<<ctime(&timeval)<<endl;
          return 0;
          }

          #include <iostream>
          #include <time.h>
          int main()
          {
          time_t curtime=time(0);
          tm tim =*localtime(&curtime);
          int day,mon,year;
          day=tim.tm_mday;
          mon=tim.tm_mon;
          year=tim.tm_year;

          std::cout<<year+1900<<"年"<<mon+1<<"月"<<day<<"日"<<std::endl;

          system("pause");
          return 0 ;
          }

          說明:struct tm
          {
          int tm_sec; /*秒,0-59*/
          int tm_min; /*分,0-59*/
          int tm_hour; /*時,0-23*/
          int tm_mday; /*天數,1-31*/
          int tm_mon; /*月數,0-11*/
          int tm_year; / *自1900的年數*/
          int tm_wday; /*自星期日的天數0-6*/
          int tm_yday; /*自1月1日起的天數,0-365*/
          int tm_isdst; /*是否采用夏時制,采用為正數*
          }

          在VC++中,我們可以借助CTime時間類,獲取系統當前日期:

          CTime t = CTime::GetCurrentTime(); //獲取系統日期

          int d=t.GetDay(); //獲得幾號

          int y=t.GetYear(); //獲取年份

          int m=t.GetMonth(); //獲取當前月份

          int h=t.GetHour(); //獲取當前為幾時

          int mm=t.GetMinute(); //獲取分鐘

          int s=t.GetSecond(); //獲取秒

          int w=t.GetDayOfWeek(); //獲取星期幾,注意1為星期天,7為星期六
          posted on 2008-04-22 22:47 -274°C 閱讀(10043) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          常用鏈接

          留言簿(21)

          隨筆分類(265)

          隨筆檔案(242)

          相冊

          JAVA網站

          關注的Blog

          搜索

          •  

          積分與排名

          • 積分 - 916101
          • 排名 - 40

          最新評論

          主站蜘蛛池模板: 香港 | 上蔡县| 田阳县| 雷山县| 瑞昌市| 铁岭市| 台湾省| 万盛区| 丰宁| 额尔古纳市| 农安县| 蒙阴县| 越西县| 东乡族自治县| 辽阳市| 扎鲁特旗| 化德县| 积石山| 集贤县| 衡水市| 阿拉尔市| 吉木萨尔县| 策勒县| 开江县| 集贤县| 日喀则市| 洞口县| 新民市| 岗巴县| 新密市| 涡阳县| 宜宾县| 大安市| 仁布县| 长岭县| 仙游县| 左贡县| 乌拉特前旗| 日喀则市| 刚察县| 若羌县|