如何读取系统日期时间呢??

woxin2003 2006-07-24 05:31:58
给个例子啊啊
...全文
355 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
KevinCEC 2006-07-26
  • 打赏
  • 举报
回复
GetLocalTime(&systime);
hhyytt 2006-07-26
  • 打赏
  • 举报
回复
GetLocalTime(&systime);
GetSystemTime(&systime);
GetCurrentTime();
asbeforelong 2006-07-26
  • 打赏
  • 举报
回复
获取当前具体时间,格式化时间
CTime t=CTime::GetCurrentTime(); //取出当前时间
int y=t.GetYear();
int d=t.GetDay();
int m=t.GetMonth();
int h=t.GetHour();
int min=t.GetMinute();
int s=t.GetSecond();

CString yy,dd,mm,hh,mins,ss,total;

yy.Format("%d",y);
dd.Format("%d",d);
mm.Format("%d",m);
if(h<10)
hh.Format("0%d",h);
else
hh.Format("%d",h);
if(min<10)
mins.Format("0%d",min);
else
mins.Format("%d",min);
if(s<10)
ss.Format("0%d",s);
else
ss.Format("%d",s);

total=yy+"-"+mm+"-"+dd+" "+hh+":"+mins+":"+ss;
MessageBox(total,"当前时间",MB_OK);

使用GetSystemTime()这个API函数得到系统时间
SYSTEMTIME ti;
GetSystemTime(&ti);
////我们可以通过读取SYSTEMTIME结构体成员直接得到时间
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME, *PSYSTEMTIME;
例如:ti.wMilliseconds;可以得到毫秒时间
GetTimeFormat 格式化时间函数
The GetTimeFormat function formats a time as a time string for a specified locale. The function formats either a specified time or the local system time.

int GetTimeFormat(
LCID Locale, // locale for which time is to be formatted
DWORD dwFlags, // flags specifying function options
CONST SYSTEMTIME *lpTime, // time to be formatted
LPCTSTR lpFormat, // time format string
LPTSTR lpTimeStr, // buffer for storing formatted string
int cchTime // size, in bytes or characters, of the buffer
);

GetDateFormat
The GetDateFormat function formats a date as a date string for a specified locale. The function formats either a specified date or the local system date.

int GetDateFormat(
LCID Locale, // locale for which date is to be formatted
DWORD dwFlags, // flags specifying function options
CONST SYSTEMTIME *lpDate, // date to be formatted
LPCTSTR lpFormat, // date format string
LPTSTR lpDateStr, // buffer for storing formatted string
int cchDate // size of buffer
);
hurryboylqs 2006-07-24
  • 打赏
  • 举报
回复
获取时间首先需要一个结构SYSTEMTIME,它主要用于GetLocalTime和GetSystemTime函数。GetSystemTime函数传回目前的世界时间(Coordinated Universal Time,UTC),大概与英国格林威治时间相同。GetLocalTime函数传回当地时间,依据计算机所在的时区。这些值的精确度完全决定于使用者所调整的时间精确度以及是否指定了正确的时区。可以双击工作列的时间显示来检查计算机上的时区设定。
saz 2006-07-24
  • 打赏
  • 举报
回复
SYSTEMTIME systime;
GetLocalTime(&systime);
sprintf(szTime, "%d-%d-%d %02d:%02d:%02d", systime.wYear, systime.wMonth, systime.wDay, systime.wHour, systime.wMinute, systime.wSecond);
snowbirdfly 2006-07-24
  • 打赏
  • 举报
回复
Changing a File Time to the Current Time

The following example sets the last-write time for a file to the current system time using the SetFileTime function.


// SetFileToCurrentTime - sets last write time to current system time
// Return value - TRUE if successful, FALSE otherwise
// hFile - must be a valid file handle

BOOL SetFileToCurrentTime(HANDLE hFile)
{
FILETIME ft;
SYSTEMTIME st;
BOOL f;

GetSystemTime(&st); // gets current time
SystemTimeToFileTime(&st, &ft); // converts to file time format
f = SetFileTime(hFile, // sets last-write time for file
(LPFILETIME) NULL, (LPFILETIME) NULL, &ft);

return f;
}
snowbirdfly 2006-07-24
  • 打赏
  • 举报
回复
void GetSystemTime(
LPSYSTEMTIME lpSystemTime
);
coolzdp 2006-07-24
  • 打赏
  • 举报
回复
CTime t = CTime::GetCurrentTime();
CString strTime = t.Format(_T("%Y-%m-%d %H:%m:%S"));
cleverwyq 2006-07-24
  • 打赏
  • 举报
回复
CTime t = CTime::GetCurrentTime();
Extraction

GetDay Returns the day represent by the CTime object.
GetDayOfWeek Returns the day of the week represented by the CTime object.
GetHour Returns the hour represented by the CTime object.
GetMinute Returns the minute represented by the CTime object.
GetMonth Returns the month represented by the CTime object.
GetSecond Returns the second represented by the CTime object.
GetTime Returns a __time64_t value for the given CTime object.
GetYear Returns the year represented by the CTime object.
wanilyer 2006-07-24
  • 打赏
  • 举报
回复
CTime t = CTime::GetCurrentTime();

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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