本文整理汇总了C++中DateFormat::getCalendar方法的典型用法代码示例。如果您正苦于以下问题:C++ DateFormat::getCalendar方法的具体用法?C++ DateFormat::getCalendar怎么用?C++ DateFormat::getCalendar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateFormat
的用法示例。
在下文中一共展示了DateFormat::getCalendar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dataerrln
/**
* @bug 4071441
*/
void DateFormatRegressionTest::Test4071441(void)
{
DateFormat *fmtA = DateFormat::createInstance();
DateFormat *fmtB = DateFormat::createInstance();
if (fmtA == NULL || fmtB == NULL){
dataerrln("Error calling DateFormat::createInstance");
delete fmtA;
delete fmtB;
return;
}
// {sfb} Is it OK to cast away const here?
Calendar *calA = (Calendar*) fmtA->getCalendar();
Calendar *calB = (Calendar*) fmtB->getCalendar();
if(!calA || !calB) {
errln("Couldn't get proper calendars, exiting");
delete fmtA;
delete fmtB;
return;
}
UDate epoch = date(0, 0, 0);
UDate xmas = date(61, UCAL_DECEMBER, 25);
UErrorCode status = U_ZERO_ERROR;
calA->setTime(epoch, status);
failure(status, "calA->setTime");
calB->setTime(epoch, status);
failure(status, "calB->setTime");
if (*calA != *calB)
errln("Fail: Can't complete test; Calendar instances unequal");
if (*fmtA != *fmtB)
errln("Fail: DateFormat unequal when Calendars equal");
calB->setTime(xmas, status);
failure(status, "calB->setTime");
if (*calA == *calB)
errln("Fail: Can't complete test; Calendar instances equal");
if (*fmtA != *fmtB)
errln("Fail: DateFormat unequal when Calendars equivalent");
logln("DateFormat.equals ok");
delete fmtA;
delete fmtB;
}
示例2: testAPI
//.........这里部分代码省略.........
}
logln( (UnicodeString) "" + d + " formatted to " + res1);
res2 = it->format(d, res2, pos2);
logln( (UnicodeString) "" + d + " formatted to " + res2);
res3 = de->format(d, res3);
logln( (UnicodeString) "" + d + " formatted to " + res3);
}
// ======= Test parse()
if (def != NULL)
{
logln("Testing parse()");
UnicodeString text("02/03/76 2:50 AM, CST");
Formattable result1;
UDate result2, result3;
ParsePosition pos(0), pos01(0);
def->parseObject(text, result1, pos);
if(result1.getType() != Formattable::kDate) {
errln("ERROR: parseObject() failed for " + text);
}
logln(text + " parsed into " + result1.getDate());
status = U_ZERO_ERROR;
result2 = def->parse(text, status);
if(U_FAILURE(status)) {
errln("ERROR: parse() failed, stopping testing");
return;
}
logln(text + " parsed into " + result2);
result3 = def->parse(text, pos01);
logln(text + " parsed into " + result3);
}
// ======= Test getters and setters
if (fr != NULL && it != NULL && de != NULL)
{
logln("Testing getters and setters");
int32_t count = 0;
const Locale *locales = DateFormat::getAvailableLocales(count);
logln((UnicodeString) "Got " + count + " locales" );
for(int32_t i = 0; i < count; i++) {
UnicodeString name;
name = locales[i].getName();
logln(name);
}
fr->setLenient(it->isLenient());
if(fr->isLenient() != it->isLenient()) {
errln("ERROR: setLenient() failed");
}
const Calendar *cal = def->getCalendar();
Calendar *newCal = cal->clone();
de->adoptCalendar(newCal);
it->setCalendar(*newCal);
if( *(de->getCalendar()) != *(it->getCalendar())) {
errln("ERROR: adopt or set Calendar() failed");
}
const NumberFormat *nf = def->getNumberFormat();
NumberFormat *newNf = (NumberFormat*) nf->clone();
de->adoptNumberFormat(newNf);
it->setNumberFormat(*newNf);
if( *(de->getNumberFormat()) != *(it->getNumberFormat())) {
errln("ERROR: adopt or set NumberFormat() failed");
}
const TimeZone& tz = def->getTimeZone();
TimeZone *newTz = tz.clone();
de->adoptTimeZone(newTz);
it->setTimeZone(*newTz);
if( de->getTimeZone() != it->getTimeZone()) {
errln("ERROR: adopt or set TimeZone() failed");
}
}
// ======= Test getStaticClassID()
logln("Testing getStaticClassID()");
status = U_ZERO_ERROR;
DateFormat *test = new SimpleDateFormat(status);
if(U_FAILURE(status)) {
errln("ERROR: Couldn't create a DateFormat");
}
if(test->getDynamicClassID() != SimpleDateFormat::getStaticClassID()) {
errln("ERROR: getDynamicClassID() didn't return the expected value");
}
delete test;
delete def;
delete fr;
delete it;
delete de;
}