一个简单的问题

gotothesun 2004-08-11 12:15:56
在VC中怎样获取当前时间,日期之类的?
...全文
112 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
memory_xj 2004-08-12
  • 打赏
  • 举报
回复
你可以用COleDateTime,如下:
COleVariant varTemp("2004-8-11");
COleDateTime oleTime(varTemp);
这样就可以将字符串“2004-8-11”最方便地转换为日期了。
Kudeet 2004-08-11
  • 打赏
  • 举报
回复
得到当前时间 日期
CTime tTime = CTime::GetCurrentTime();
gotothesun 2004-08-11
  • 打赏
  • 举报
回复
谢谢,但是CTime类好像只能用来获得系统时间,我能不能将一个字符串的时间放在CTime对象里呢?因为CTime的成员函数都是Get开头,没有Set开头的。
oyljerry 2004-08-11
  • 打赏
  • 举报
回复
CTime::GetDay
Returns the day represent by the CTime object.

int GetDay( ) const throw( );
Return Value
Returns the day of the month, based on local time, in the range 1 through 31.

Remarks
This function calls GetLocalTm, which uses an internal, statically allocated buffer. The data in this buffer is overwritten because of calls to other CTime member functions.

Example
// Example for CTime::GetDay, CTime::GetMonth, and CTime::GetYear
CTime t( 1999, 3, 19, 22, 15, 0 ); // 10:15 PM March 19, 1999
ATLASSERT( t.GetDay() == 19 );
ATLASSERT( t.GetMonth() == 3 );
ATLASSERT( t.GetYear() == 1999 );
oyljerry 2004-08-11
  • 打赏
  • 举报
回复
CTime::GetCurrentTime
Returns a CTime object that represents the current time.

static CTime WINAPI GetCurrentTime( ) throw( );
Example
// Example for CTime::GetCurrentTime
CTime t = CTime::GetCurrentTime();
远志999 2004-08-11
  • 打赏
  • 举报
回复
CTime time=CTime::GetCurrentTime();
或者
CTime time=CTime::GetLocalTime();
lishan2002 2004-08-11
  • 打赏
  • 举报
回复
总结楼上的:
法一: CTime time;
time=CTime::GetCurrentTime();
法二:GetSystemTime(&systime);
问道er 2004-08-11
  • 打赏
  • 举报
回复
用SYSTEMTIME,可以精确到毫秒
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
} SYSTEMTIME;

GetSystemTime()函数用于取时间,SetSystemTime()用于设置系统时间,

另外,你还可以用GetLocalTime()取得当地的当前时间,而不是UTC时间,当然,对应的有SetLocalTime函数;

UTC时间和当地时间可以通过使用SetTimeZoneInformation函数设置当前时区参数来控制;

用SystemTimeToFileTime函数可以将SYSTEMTIME格式转换为FILETIME格式;

16,548

社区成员

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

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

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