MFC日期时间选择器零值

时间:2012-03-21 15:01:23

标签: c++ mfc

是否可以在时间模式下将其值设置为0?我试过了

CTime time;
m_Time.setTime(&time);

,但显示1:0:0。有什么建议吗?

1 个答案:

答案 0 :(得分:2)

是的,有可能,请参阅下面的strTime,其值为“0:0:0”。但是,如果您正在寻找时间间隔而不是实际时间,请更好地使用CTimeSpan,请参阅下文。

   time_t date1_t, date2_t;
   tm date_tm;

   date_tm.tm_hour   =0;
   date_tm.tm_min   =0;
   date_tm.tm_mon   =0;
   date_tm.tm_sec   =0;
   date_tm.tm_wday   =0; //Day of week (0-6; Sunday = 0)
   date_tm.tm_yday =1;
   date_tm.tm_year   =97;
   date_tm.tm_isdst =-1; //Positive if Daylight Saving Time is in effect;
                         //0 if Daylight Saving Time is not in effect; 
                         //Negative if status of DST is unknown.

   date_tm.tm_mday   =0;
   date2_t = mktime(&date_tm);

   date_tm.tm_mday   =0;
   date_tm.tm_isdst =0;
   date1_t = mktime(&date_tm);

   CTime time1(date1_t), time2(date2_t);
   CTimeSpan ts = time2 - time1;
   CString strTime = time1.Format("%H:%M:%S");