本文整理汇总了C++中SimpleDateFormat::adoptCalendar方法的典型用法代码示例。如果您正苦于以下问题:C++ SimpleDateFormat::adoptCalendar方法的具体用法?C++ SimpleDateFormat::adoptCalendar怎么用?C++ SimpleDateFormat::adoptCalendar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleDateFormat
的用法示例。
在下文中一共展示了SimpleDateFormat::adoptCalendar方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pattern
void DateFormatRegressionTest::Test5554(void)
{
UErrorCode status = U_ZERO_ERROR;
UnicodeString pattern("Z","");
UnicodeString newfoundland("Canada/Newfoundland", "");
TimeZone *zone = TimeZone::createTimeZone(newfoundland);
Calendar *cal = new GregorianCalendar(zone, status);
SimpleDateFormat *sdf = new SimpleDateFormat(pattern,status);
if (U_FAILURE(status)) {
dataerrln("Error constructing SimpleDateFormat");
delete cal;
delete sdf;
return;
}
cal->set(2007, 1, 14);
UDate date = cal->getTime(status);
if (U_FAILURE(status)) {
errln("Error getting time to format");
return;
};
sdf->adoptCalendar(cal);
UnicodeString result;
UnicodeString correct("-0330", "");
sdf->format(date, result);
if (result != correct) {
errln("\nError: Newfoundland Z of Jan 14, 2007 gave '" + result + "', expected '" + correct + "'");
}
delete sdf;
}
示例2: SimpleDateFormat
std::string L10n::FormatMillisecondsIntoDateString(const UDate& milliseconds, const std::string& formatString) const
{
UErrorCode status = U_ZERO_ERROR;
UnicodeString dateString;
std::string resultString;
UnicodeString unicodeFormat = UnicodeString::fromUTF8(formatString.c_str());
SimpleDateFormat* dateFormat = new SimpleDateFormat(unicodeFormat, status);
if (U_FAILURE(status))
LOGERROR("Error creating SimpleDateFormat: %s", u_errorName(status));
const TimeZone* timeZone = TimeZone::getGMT();
status = U_ZERO_ERROR;
Calendar* calendar = Calendar::createInstance(*timeZone, currentLocale, status);
if (U_FAILURE(status))
LOGERROR("Error creating calendar: %s", u_errorName(status));
dateFormat->adoptCalendar(calendar);
dateFormat->format(milliseconds, dateString);
delete dateFormat;
dateString.toUTF8String(resultString);
return resultString;
}