胡斌老师弟子规:VC++中如何取得时间?

来源:百度文库 编辑:中科新闻网 时间:2024/05/12 15:19:21
具体问题为:如何取得当前系统时间,怎么样在系统时间加上100天,然后格式输出。
帮写出正确程序代码,谢谢!

//方案— 优点:仅使用C标准库;缺点:只能精确到秒级

#include

#include

int main( void )

{

time_t t = time( 0 );

char tmp[64];

strftime( tmp, sizeof(tmp), "%Y/%m/%d %X %A 本年第%j天 %z",

localtime(&t) );

puts( tmp );

return 0;

}

//方案二 优点:能精确到毫秒级;缺点:使用了windows API

#include

#include

int main( void )

{

SYSTEMTIME sys;

GetLocalTime( &sys );

printf( "%4d/%02d/%02d %02d:%02d:%02d.%03d 星期%1d\n"

,sys.wYear,sys.wMonth,sys.wDay

,sys.wHour,sys.wMinute,sys.wSecond,sys.wMilliseconds

,sys.wDayOfWeek);

return 0;
}

//方案三,优点:利用系统函数
#include
#include
using namespace std;
void main(){
system("time");
}
可以改变电脑的时间设定

方案4:
#include

#include

using namespace std;

int main()
{
time_t now_time;
now_time = time(NULL);
cout<

return 0;

}
另一:_strdate(tempstr);
另二:
CString CTestView::GetTime()
{

CTime CurrentTime=CTime::GetCurrentTime();
CString strTime;
strTime.Format("%d:%d:%d",CurrentTime.GetHour(), CurrentTime.GetMinute(),CurrentTime.GetSecond());

return strTime;
} language=VBScript>call ReplaceSubjectHTML_emote(592915)

以上是复制粘贴的

输出直接在DC上 textout就可以了