
得到系统时间:
1使用CTime类
CTime tm=CTime::GetCurrentTime();
CString str=tmFormat(“现在时间是:%Y年%m月%d日 %X”);
MessageBox(str,NULL,MB_OK);
2: 得到系统时间日期(使用GetLocalTime)
SYSTEMTIME st;
CString strDate,strTime;
GetLocalTime(&st);
strDateFormat(“%4d-%2d-%2d”,stwYear,stwMonth,stwDay);
strTimeFormat(“%2d:%2d:%2d”,stwHour,stwMinute,stwSecond);
3使用GetTickCount//获取程序运行时间
long t1=GetTickCount();//程序段开始前取得系统运行时间(ms)
……//程序段
long t2=GetTickCount();//程序段结束后取得系统运行时间(ms)
long t = t2-t1; //前后之差即 程序运行时间 (ms)
void CClockDlg::CurrentTime()
{
time_t tCurrentTime;
///声明
char szBuffer [ 256 ];
// 获取系统时间
tCurrentTime = time ( ( time_t ) NULL );
////////////
strftime ( szBuffer, sizeof ( szBuffer ), "%H", localtime ( &tCurrentTime ) );
m_hours = szBuffer;
strftime ( szBuffer, sizeof ( szBuffer ), "%M", localtime ( &tCurrentTime ) );
m_minutes = szBuffer;
strftime ( szBuffer, sizeof ( szBuffer ), "%S", localtime ( &tCurrentTime ) );
m_seconds = szBuffer;
// 将各变量值赋给对话框相应ID号 对应的项
( GetDlgItem ( IDC_HOUR ) ) -> SetWindowText ( m_hours );
( GetDlgItem ( IDC_MINUTE ) ) -> SetWindowText ( m_minutes );
( GetDlgItem ( IDC_SECOND ) ) -> SetWindowText ( m_seconds );
}
SetTimer一个刷新频率,然后在窗口的OnTimer中,定时刷新调用就可以了。
11 获得当前日期+时间(date + time)函数:now()
除了 now() 函数能获得当前的日期时间外,MySQL 中还有下面的函数:
current_timestamp() current_timestamp
localtime() localtime
localtimestamp() localtimestamp
这些日期时间函数,都等同于 now()。鉴于 now() 函数简短易记,建议总是使用 now() 来替代上面列出的函数。
12 获得当前日期+时间(date + time)函数:sysdate()
sysdate() 日期时间函数跟 now() 类似,不同之处在于:now() 在执行开始时值就得到了, sysdate() 在函数执行时动态得到值。
2 获得当前日期(date)函数:curdate()
其中,下面的两个日期函数等同于 curdate(): current_date(),current_date
3 获得当前时间(time)函数:curtime()
其中,下面的两个时间函数等同于 curtime():current_time(),current_time
4 获得当前 UTC 日期时间函数:utc_date(), utc_time(), utc_timestamp()
楼上多数正确。
function getdate(){
var today = new Date();
var y = todaygetFullYear();
//为了兼容谷歌和火狐所以使用getFullYear,IE可以直接识别getFullYear为大日期,
var m = todaygetMonth()+1;
m = m > 9 m : "0" + m;
var d = todaygetDate();
d = d>9d:"0"+d;
var date = y+"-"+m+"-"+d;
return date;
}
以上就是关于C语言中怎样调用系统时间并动态显示!全部的内容,包括:C语言中怎样调用系统时间并动态显示!、求解,如何用C++动态显示当前系统时间最好附有注释、mysql如何获取当前时间等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)