关于时间?

gxy19830818 2004-04-11 07:44:19
请问各位老大,在c++里用哪一个函数获得系统的时间?
...全文
108 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
gxy19830818 2004-04-16
  • 打赏
  • 举报
回复
谢谢各位了,结贴
httruly 2004-04-14
  • 打赏
  • 举报
回复
学习
lyzq 2004-04-13
  • 打赏
  • 举报
回复
SYSTEMTIME st;
GetSystemTime(&st);
hslinux 2004-04-13
  • 打赏
  • 举报
回复
装个VC&MSDN,什么都知道了。
happlyman 2004-04-11
  • 打赏
  • 举报
回复
#include <time.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <string.h>


int main(int argc, char* argv[])
{
char tmpbuf[128], ampm[] = "AM";
time_t ltime;
struct _timeb tstruct;
struct tm *today, *gmt, xmas = { 0, 0, 12, 25, 11, 93 };

_tzset();

_strtime( tmpbuf );
printf( "OS time:\t\t\t\t%s\n", tmpbuf );
_strdate( tmpbuf );
printf( "OS date:\t\t\t\t%s\n", tmpbuf );

time( <ime );
printf( "Time in seconds since UTC 1/1/70:\t%ld\n", ltime );
printf( "UNIX time and date:\t\t\t%s", ctime( <ime ) );

gmt = gmtime( <ime );
printf( "Coordinated universal time:\t\t%s", asctime( gmt ) );

today = localtime( <ime );
if( today->tm_hour > 12 )
{
strcpy( ampm, "PM" );
today->tm_hour -= 12;
}
if( today->tm_hour == 0 ) /* Adjust if midnight hour. */
today->tm_hour = 12;

printf( "12-hour time:\t\t\t\t%.8s %s\n",
asctime( today ) + 11, ampm );

_ftime( &tstruct );
printf( "Plus milliseconds:\t\t\t%u\n", tstruct.millitm );
printf( "Zone difference in seconds from UTC:\t%u\n",
tstruct.timezone );
printf( "Time zone name:\t\t\t\t%s\n", _tzname[0] );
printf( "Daylight savings:\t\t\t%s\n",
tstruct.dstflag ? "YES" : "NO" );

if( mktime( &xmas ) != (time_t)-1 )
printf( "Christmas\t\t\t\t%s\n", asctime( &xmas ) );

today = localtime( <ime );

strftime( tmpbuf, 128,
"Today is %A, day %d of %B in the year %Y.\n", today );
printf( tmpbuf );

return 0;
}
rorot 2004-04-11
  • 打赏
  • 举报
回复
#include <ctime>
#include <iostream>

using namespace std;


int main()
// 时间
{
time_t t0;

time( &t0 );
tm *t1 = localtime(&t0);

cout << t1->tm_year+1900 << endl;
cout << t1->tm_mon+1 << endl;
cout << t1->tm_mday << endl;
cout << t1->tm_hour << endl;

return 0;
}

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧