一个简单 C 代码,能获取系统当前时间并输出显示:
time.h 有个函数能用
unsigned __cdecl _getsystime(struct tm *)
struct tm {
int tm_sec; /* seconds after the minute - [0,59] */
int tm_min; /* minutes after the hour - [0,59] */
int tm_hour; /* hours since midnight - [0,23] */
int tm_mday; /* day of the month - [1,31] */
int tm_mon; /* months since January - [0,11] */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday - [0,6] */
int tm_yday; /* days since January 1 - [0,365] */
int tm_isdst; /* daylight savings time flag */
};
CTime now = CTime::GetCurrentTime();
CString s = now.Format("%Y-%m-%d %H:%M:%S");
cout << (LPCSTR)s << endl;
// Example for COleDateTime::GetCurrentTime.
COleDateTime dateTest;
// dateTest value = midnight 30 December 1899
dateTest = COleDateTime::GetCurrentTime();
// dateTest value = current date and time
// A second example for COleDateTime::GetCurrentTime.
// Since GetCurrentTime() is a static member, you can use it in
// a constructor:
COleDateTime t1 = COleDateTime::GetCurrentTime();
COleDateTime t2(COleDateTime::GetCurrentTime());
// Or in a normal assignment operator
COleDateTime t3;
t3 = COleDateTime::GetCurrentTime();
// or even in an expression
if (COleDateTime::GetCurrentTime().GetDayOfWeek() == 6)
_tprintf(_T("Thank Goodness it is Friday!"));
tm tm1;
_getsystime(&tm1);
printf("%d-%d-%d %d:%d:%d",tm1.tm_year+1900,tm1.tm_mon+1,tm1.tm_mday,tm1.t
m_hour,tm1.tm_min,tm1.tm_sec);;
评论0