本文整理汇总了C++中CTime::SetFormat方法的典型用法代码示例。如果您正苦于以下问题:C++ CTime::SetFormat方法的具体用法?C++ CTime::SetFormat怎么用?C++ CTime::SetFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CTime
的用法示例。
在下文中一共展示了CTime::SetFormat方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: s_TestGMT
static void s_TestGMT(int idx)
{
// Write time in timezone format
{{
CTime::SetFormat("M/D/Y h:m:s Z");
CTime t1(2001, 3, 12, 11, 22, 33, 999, CTime::eGmt);
assert(t1.AsString() == "03/12/2001 11:22:33 GMT");
CTime t2(2001, 3, 12, 11, 22, 33, 999, CTime::eLocal);
assert(t2.AsString() == "03/12/2001 11:22:33 ");
}}
// Process timezone string
{{
CTime t;
t.SetFormat("M/D/Y h:m:s Z");
t="03/12/2001 11:22:33 GMT";
assert(t.AsString() == "03/12/2001 11:22:33 GMT");
t="03/12/2001 11:22:33 ";
assert(t.AsString() == "03/12/2001 11:22:33 ");
}}
// Day of week
{{
CTime t(2001, 4, 1);
t.SetFormat("M/D/Y h:m:s w");
int i;
for (i=0; t<=CTime(2001, 4, 10); t.AddDay(),i++) {
assert(t.DayOfWeek() == (i%7));
}
}}
// Test GetTimeT
{{
time_t timer = time(0);
CTime tgmt(CTime::eCurrent, CTime::eGmt, CTime::eTZPrecisionDefault);
CTime tloc(CTime::eCurrent, CTime::eLocal, CTime::eTZPrecisionDefault);
CTime t(timer);
// Set the same time to all time objects
tgmt.SetTimeT(timer);
tloc.SetTimeT(timer);
assert(timer == t.GetTimeT());
assert(timer == tgmt.GetTimeT());
// On the day of changing to summer/winter time, the local time
// converted to GMT may differ from the value returned by time(0),
// because in the common case API don't know if DST is in effect for
// specified local time or not (see mktime()).
time_t l_ = tloc.GetTimeT();
if (timer != l_ ) {
if ( abs((int)(timer - l_)) > 3600 )
assert(timer == l_);
}
}}
// Test TimeZoneOffset (1) -- EST timezone only
{{
CTime tw(2001, 1, 1, 12);
CTime ts(2001, 6, 1, 12);
assert(tw.TimeZoneOffset() / 3600 == -5);
assert(ts.TimeZoneOffset()/3600 == -4);
}}
// Test TimeZoneOffset (2) -- EST timezone only
{{
CTime tw(2001, 6, 1, 12);
CTime ts(2002, 1, 1, 12);
assert(tw.TimeZoneOffset() / 3600 == -4);
assert(ts.TimeZoneOffset() / 3600 == -5);
}}
// Test AdjustTime
{{
CTime::SetFormat("M/D/Y h:m:s");
CTime t("03/11/2007 01:01:00");
CTime tn;
t.SetTimeZonePrecision(CTime::eTZPrecisionDefault);
// GMT
t.SetTimeZone(CTime::eGmt);
tn = t;
tn.AddDay(5);
assert(tn.AsString() == "03/16/2007 01:01:00");
tn = t;
tn.AddDay(40);
assert(tn.AsString() == "04/20/2007 01:01:00");
// Local eNone
t.SetTimeZone(CTime::eLocal);
t.SetTimeZonePrecision(CTime::eNone);
tn = t;
tn.AddDay(5);
assert(tn.AsString() == "03/16/2007 01:01:00");
tn = t;
tn.AddDay(40);
assert(tn.AsString() == "04/20/2007 01:01:00");
//Local eMonth
t.SetTimeZonePrecision(CTime::eMonth);
tn = t;
tn.AddDay(5);
//.........这里部分代码省略.........