本文整理汇总了C++中SimpleDateFormat::setDateFormatSymbols方法的典型用法代码示例。如果您正苦于以下问题:C++ SimpleDateFormat::setDateFormatSymbols方法的具体用法?C++ SimpleDateFormat::setDateFormatSymbols怎么用?C++ SimpleDateFormat::setDateFormatSymbols使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleDateFormat
的用法示例。
在下文中一共展示了SimpleDateFormat::setDateFormatSymbols方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DateFormatSymbols
void
DateFormatMiscTests::test4099975()
{
/**
* Test Constructor SimpleDateFormat::SimpleDateFormat (const UnicodeString & pattern,
* const DateFormatSymbols & formatData, UErrorCode & status )
* The DateFormatSymbols object is NOT adopted; Modifying the original DateFormatSymbols
* should not change the SimpleDateFormat's behavior.
*/
UDate d = Calendar::getNow();
{
UErrorCode status = U_ZERO_ERROR;
DateFormatSymbols* symbols = new DateFormatSymbols(Locale::getUS(), status);
if(failure(status, "new DateFormatSymbols")) return;
SimpleDateFormat *df = new SimpleDateFormat(UnicodeString("E hh:mm"), *symbols, status);
if(failure(status, "new SimpleDateFormat")) return;
UnicodeString format0;
format0 = df->format(d, format0);
UnicodeString localizedPattern0;
localizedPattern0 = df->toLocalizedPattern(localizedPattern0, status);
failure(status, "df->toLocalizedPattern");
symbols->setLocalPatternChars(UnicodeString("abcdefghijklmonpqr")); // change value of field
UnicodeString format1;
format1 = df->format(d, format1);
if (format0 != format1) {
errln(UnicodeString("Formats are different. format0: ") + format0
+ UnicodeString("; format1: ") + format1);
}
UnicodeString localizedPattern1;
localizedPattern1 = df->toLocalizedPattern(localizedPattern1, status);
failure(status, "df->toLocalizedPattern");
if (localizedPattern0 != localizedPattern1) {
errln(UnicodeString("Pattern has been changed. localizedPattern0: ") + localizedPattern0
+ UnicodeString("; localizedPattern1: ") + localizedPattern1);
}
delete symbols;
delete df;
}
/*
* Test void SimpleDateFormat::setDateFormatSymbols ( const DateFormatSymbols & newFormatSymbols )
* Modifying the original DateFormatSymbols should not change the SimpleDateFormat's behavior.
*/
{
UErrorCode status = U_ZERO_ERROR;
DateFormatSymbols* symbols = new DateFormatSymbols(Locale::getUS(), status);
if(failure(status, "new DateFormatSymbols")) return;
SimpleDateFormat *df = new SimpleDateFormat(UnicodeString("E hh:mm"), status);
if(failure(status, "new SimpleDateFormat")) return;
df->setDateFormatSymbols(*symbols);
UnicodeString format0;
format0 = df->format(d, format0);
UnicodeString localizedPattern0;
localizedPattern0 = df->toLocalizedPattern(localizedPattern0, status);
failure(status, "df->toLocalizedPattern");
symbols->setLocalPatternChars(UnicodeString("abcdefghijklmonpqr")); // change value of field
UnicodeString format1;
format1 = df->format(d, format1);
if (format0 != format1) {
errln(UnicodeString("Formats are different. format0: ") + format0
+ UnicodeString("; format1: ") + format1);
}
UnicodeString localizedPattern1;
localizedPattern1 = df->toLocalizedPattern(localizedPattern1, status);
failure(status, "df->toLocalizedPattern");
if (localizedPattern0 != localizedPattern1) {
errln(UnicodeString("Pattern has been changed. localizedPattern0: ") + localizedPattern0
+ UnicodeString("; localizedPattern1: ") + localizedPattern1);
}
delete symbols;
delete df;
}
//Test the pointer version of the constructor (and the adoptDateFormatSymbols method)
{
UErrorCode status = U_ZERO_ERROR;
DateFormatSymbols* symbols = new DateFormatSymbols(Locale::getUS(), status);
if(failure(status, "new DateFormatSymbols")) return;
SimpleDateFormat *df = new SimpleDateFormat(UnicodeString("E hh:mm"), symbols, status);
if(failure(status, "new SimpleDateFormat")) return;
UnicodeString format0;
format0 = df->format(d, format0);
UnicodeString localizedPattern0;
localizedPattern0 = df->toLocalizedPattern(localizedPattern0, status);
failure(status, "df->toLocalizedPattern");
symbols->setLocalPatternChars(UnicodeString("abcdefghijklmonpqr")); // change value of field
UnicodeString format1;
format1 = df->format(d, format1);
if (format0 != format1) {
errln(UnicodeString("Formats are different. format0: ") + format0
+ UnicodeString("; format1: ") + format1);
}
UnicodeString localizedPattern1;
localizedPattern1 = df->toLocalizedPattern(localizedPattern1, status);
failure(status, "df->toLocalizedPattern");
if (localizedPattern0 == localizedPattern1) {
errln(UnicodeString("Pattern should have been changed. localizedPattern0: ") + localizedPattern0
+ UnicodeString("; localizedPattern1: ") + localizedPattern1);
}
//delete symbols; the caller is no longer responsible for deleting the symbols
delete df;
//.........这里部分代码省略.........