本文整理汇总了C++中SimpleDateFormat::setCalendar方法的典型用法代码示例。如果您正苦于以下问题:C++ SimpleDateFormat::setCalendar方法的具体用法?C++ SimpleDateFormat::setCalendar怎么用?C++ SimpleDateFormat::setCalendar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleDateFormat
的用法示例。
在下文中一共展示了SimpleDateFormat::setCalendar方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pos
UBool
TimeZoneRegressionTest::checkCalendar314(GregorianCalendar *testCal, TimeZone *testTZ)
{
UErrorCode status = U_ZERO_ERROR;
// GregorianCalendar testCal = (GregorianCalendar)aCal.clone();
int32_t tzOffset, tzRawOffset;
float tzOffsetFloat,tzRawOffsetFloat;
// Here is where the user made an error. They were passing in the value of
// the MILLSECOND field; you need to pass in the millis in the day in STANDARD
// time.
UDate millis = testCal->get(UCAL_MILLISECOND, status) +
1000.0 * (testCal->get(UCAL_SECOND, status) +
60.0 * (testCal->get(UCAL_MINUTE, status) +
60.0 * (testCal->get(UCAL_HOUR_OF_DAY, status)))) -
testCal->get(UCAL_DST_OFFSET, status);
/* Fix up millis to be in range. ASSUME THAT WE ARE NOT AT THE
* BEGINNING OR END OF A MONTH. We must add this code because
* getOffset() has been changed to be more strict about the parameters
* it receives -- it turns out that this test was passing in illegal
* values. */
int32_t date = testCal->get(UCAL_DATE, status);
int32_t dow = testCal->get(UCAL_DAY_OF_WEEK, status);
while(millis < 0) {
millis += U_MILLIS_PER_DAY;
--date;
dow = UCAL_SUNDAY + ((dow - UCAL_SUNDAY + 6) % 7);
}
while (millis >= U_MILLIS_PER_DAY) {
millis -= U_MILLIS_PER_DAY;
++date;
dow = UCAL_SUNDAY + ((dow - UCAL_SUNDAY + 1) % 7);
}
tzOffset = testTZ->getOffset((uint8_t)testCal->get(UCAL_ERA, status),
testCal->get(UCAL_YEAR, status),
testCal->get(UCAL_MONTH, status),
date,
(uint8_t)dow,
(int32_t)millis,
status);
tzRawOffset = testTZ->getRawOffset();
tzOffsetFloat = (float)tzOffset/(float)3600000;
tzRawOffsetFloat = (float)tzRawOffset/(float)3600000;
UDate testDate = testCal->getTime(status);
UBool inDaylightTime = testTZ->inDaylightTime(testDate, status);
SimpleDateFormat *sdf = new SimpleDateFormat((UnicodeString)"MM/dd/yyyy HH:mm", status);
sdf->setCalendar(*testCal);
UnicodeString inDaylightTimeString;
UBool passed;
if(inDaylightTime)
{
inDaylightTimeString = " DST ";
passed = (tzOffset == (tzRawOffset + 3600000));
}
else
{
inDaylightTimeString = " ";
passed = (tzOffset == tzRawOffset);
}
UnicodeString output;
FieldPosition pos(0);
output = testTZ->getID(output) + " " + sdf->format(testDate, output, pos) +
" Offset(" + tzOffsetFloat + ")" +
" RawOffset(" + tzRawOffsetFloat + ")" +
" " + millis/(float)3600000 + " " +
inDaylightTimeString;
if (passed)
output += " ";
else
output += "ERROR";
if (passed)
logln(output);
else
errln(output);
delete sdf;
return passed;
}