#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時間類,獲取系統(tǒng)當前日期:

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

          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 閱讀(10037) 評論(0)  編輯  收藏

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


          網站導航:
           

          常用鏈接

          留言簿(21)

          隨筆分類(265)

          隨筆檔案(242)

          相冊

          JAVA網站

          關注的Blog

          搜索

          •  

          積分與排名

          • 積分 - 914107
          • 排名 - 40

          最新評論

          主站蜘蛛池模板: 乌拉特中旗| 北川| 涪陵区| 贵州省| SHOW| 北海市| 石林| 淮滨县| 平昌县| 出国| 锡林郭勒盟| 潍坊市| 从化市| 吴堡县| 兴海县| 兴城市| 建湖县| 云和县| 霍山县| 哈尔滨市| 长丰县| 滦平县| 乌鲁木齐市| 威宁| 定安县| 海林市| 汉阴县| 都昌县| 隆化县| 邛崃市| 二手房| 汤阴县| 收藏| 巢湖市| 监利县| 芒康县| 环江| 永嘉县| 吉首市| 理塘县| 宁陕县|