posts - 131,  comments - 234,  trackbacks - 0
#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 阅读(286) 评论(0)  编辑  收藏

标题  
姓名  
主页
内容(请不要发表任何与政治相关的内容)  
登录后才能发表评论
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      
 

<2008年4月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

黄树林里分叉两条路,而我,我选择了较少人迹的一条,使得一切多麽地不同。


常用链接

留言簿(11)

随笔分类(136)

随笔档案(131)

JAVA网站

关注的Blog

最新随笔

搜索

  •  

积分与排名

  • 积分 - 73889
  • 排名 - 104

最新评论

阅读排行榜

评论排行榜