c++中获取系统时间有关问题
c++中获取系统时间问题
#include <time.h>
#include <iostream>
using namespace std;
int main( void )
{
int year;
time_t t = time(0);
char tmp[64];
strftime( tmp, sizeof(tmp), "%Y",localtime(&t) );
year=tmp;
cout<<year<<endl;
//puts( tmp );
return 0;
}
请问一下怎样将获取的时间进行调用
------解决方案--------------------
//
另一种
------解决方案--------------------
bcb控制台程序可以使用vcl 可以用Now()获得当前时间 。
------解决方案--------------------
2楼 最简单 ,用now 可以获取包括年月日时分秒在内的时间
date 只获取日期 ,time 只获取时间
你用相应的数据类型的变量接受就可以使用了,需要的话再转换成AnsiString
#include <time.h>
#include <iostream>
using namespace std;
int main( void )
{
int year;
time_t t = time(0);
char tmp[64];
strftime( tmp, sizeof(tmp), "%Y",localtime(&t) );
year=tmp;
cout<<year<<endl;
//puts( tmp );
return 0;
}
请问一下怎样将获取的时间进行调用
------解决方案--------------------
//
TDateTime dt = TDateTime().CurrentDateTime();
AnsiString strCurrDt = dt.FormatString("yyyy-mm-dd hh:nn");
另一种
inline void _MyOutputDbgString(char* lpDbgInfo)
{
char lpOutMsg[_DEBUG_BUFFER_SIZE_] = {0x00};
SYSTEMTIME sysTime;
GetLocalTime(&sysTime);
sprintf(lpOutMsg,"[%d:%d:%d.%d]:%s\r\n",sysTime.wHour,sysTime.wMinute,sysTime.wSecond,sysTime.wMilliseconds,lpDbgInfo);
printf(lpOutMsg);
OutputDebugString(lpOutMsg);
}
------解决方案--------------------
bcb控制台程序可以使用vcl 可以用Now()获得当前时间 。
------解决方案--------------------
2楼 最简单 ,用now 可以获取包括年月日时分秒在内的时间
date 只获取日期 ,time 只获取时间
你用相应的数据类型的变量接受就可以使用了,需要的话再转换成AnsiString