本文整理汇总了C++中CTime::AsString方法的典型用法代码示例。如果您正苦于以下问题:C++ CTime::AsString方法的具体用法?C++ CTime::AsString怎么用?C++ CTime::AsString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CTime
的用法示例。
在下文中一共展示了CTime::AsString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetToTime
void CDate::SetToTime(const CTime& time, CDate::EPrecision prec)
{
switch (Which()) {
case e_not_set:
case e_Std:
SetStd().SetToTime(time, prec);
break;
case e_Str:
SetStr(time.AsString());
break;
}
}
示例2: s_TestMisc
static void s_TestMisc(int idx)
{
// AsString()
{{
CTime t1;
assert(t1.AsString() == "");
CTime t2(2000, 365 / 2);
t2.SetFormat("M/D/Y h:m:s");
assert(t2.AsString() == "06/30/2000 00:00:00");
}}
// Year 2000 problem
{{
CTime t(1999, 12, 30);
t.SetFormat("M/D/Y");
t.AddDay();
assert(t.AsString() == "12/31/1999");
t.AddDay();
assert(t.AsString() == "01/01/2000");
t.AddDay();
assert(t.AsString() == "01/02/2000");
t="02/27/2000";
t.AddDay();
assert(t.AsString() == "02/28/2000");
t.AddDay();
assert(t.AsString() == "02/29/2000");
t.AddDay();
assert(t.AsString() == "03/01/2000");
t.AddDay();
assert(t.AsString() == "03/02/2000");
}}
// String assignment
{{
CTime::SetFormat("M/D/Y h:m:s");
CTime t("02/15/2000 01:12:33");
assert(t.AsString() == "02/15/2000 01:12:33");
t = "3/16/2001 02:13:34";
assert(t.AsString() == "03/16/2001 02:13:34");
}}
CTime::SetFormat("M/D/Y h:m:s.S");
// Adding Nanoseconds
{{
CTime t;
for (CTime ti(1999, 12, 31, 23, 59, 59, 999999995);
ti <= CTime(2000, 1, 1, 0, 0, 0, 000000003);
t = ti, ti.AddNanoSecond(2)) {
}
assert(t.AsString() == "01/01/2000 00:00:00.000000003");
}}
CTime::SetFormat("M/D/Y h:m:s");
// Adding seconds
{{
CTime t;
for (CTime ti(1999, 12, 31, 23, 59, 5);
ti <= CTime(2000, 1, 1, 0, 1, 20);
t = ti, ti.AddSecond(11)) {
}
assert(t.AsString() == "01/01/2000 00:01:17");
}}
// Adding minutes
{{
CTime t;
for (CTime ti(1999, 12, 31, 23, 45);
ti <= CTime(2000, 1, 1, 0, 15);
t = ti, ti.AddMinute(11)) {
}
assert(t.AsString() == "01/01/2000 00:07:00");
}}
// Adding hours
{{
CTime t;
for (CTime ti(1999, 12, 31); ti <= CTime(2000, 1, 1, 15);
t = ti, ti.AddHour(11)) {
}
assert(t.AsString() == "01/01/2000 09:00:00");
}}
// Adding months
{{
CTime t;
for (CTime ti(1998, 12, 29); ti <= CTime(1999, 4, 1);
t = ti, ti.AddMonth()) {
}
assert(t.AsString() == "03/28/1999 00:00:00");
}}
// Difference
{{
CTime t1(2000, 10, 1, 12, 3, 45,1);
CTime t2(2000, 10, 2, 14, 55, 1,2);
assert((t2.DiffDay(t1)-1.12) < 0.01);
//.........这里部分代码省略.........
示例3: 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);
//.........这里部分代码省略.........