本文整理汇总了C++中CIMDateTime::set方法的典型用法代码示例。如果您正苦于以下问题:C++ CIMDateTime::set方法的具体用法?C++ CIMDateTime::set怎么用?C++ CIMDateTime::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CIMDateTime
的用法示例。
在下文中一共展示了CIMDateTime::set方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _localizeDateTime
String IndicationFormatter::_localizeDateTime(
const CIMDateTime & propertyValueDateTime,
const Locale & locale)
{
PEG_METHOD_ENTER (TRC_IND_FORMATTER,
"IndicationFormatter::_localizeDateTime");
// Convert dateTimeValue to be microSeconds,
// the number of microseconds from the epoch starting
// 0/0/0000 (12 am Jan 1, 1BCE)
//
CIMDateTime dateTimeValue = propertyValueDateTime;
Uint64 dateTimeValueInMicroSecs =
dateTimeValue.toMicroSeconds();
// In ICU, as UTC milliseconds from the epoch starting
// (1 January 1970 0:00 UTC)
CIMDateTime dt;
dt.set("19700101000000.000000+000");
// Convert dateTimeValue to be milliSeconds,
// the number of milliSeconds from the epoch starting
// (1 January 1970 0:00 UTC)
UDate dateTimeValueInMilliSecs =
(Sint64)(dateTimeValueInMicroSecs - dt.toMicroSeconds())/1000;
// Create a formatter for DATE and TIME with medium length
// such as Jan 12, 1952 3:30:32pm
DateFormat *fmt;
try
{
if (locale == 0)
{
fmt = DateFormat::createDateTimeInstance(DateFormat::MEDIUM,
DateFormat::MEDIUM);
}
else
{
fmt = DateFormat::createDateTimeInstance(DateFormat::MEDIUM,
DateFormat::MEDIUM,
locale);
}
}
catch(Exception& e)
{
PEG_TRACE_STRING(TRC_IND_FORMATTER, Tracer::LEVEL4, e.getMessage());
PEG_METHOD_EXIT();
return (dateTimeValue.toString());
}
catch(...)
{
PEG_TRACE_STRING(TRC_IND_FORMATTER, Tracer::LEVEL4,
"Caught General Exception During DateFormat::createDateTimeInstance");
PEG_METHOD_EXIT();
return (dateTimeValue.toString());
}
if (fmt == 0)
{
PEG_TRACE_STRING(TRC_IND_FORMATTER, Tracer::LEVEL4,
"Memory allocation error creating DateTime instance.");
PEG_METHOD_EXIT();
return (dateTimeValue.toString());
}
// Format the Date and Time
UErrorCode status = U_ZERO_ERROR;
UnicodeString dateTimeUniStr;
fmt->format(dateTimeValueInMilliSecs, dateTimeUniStr, status);
if (U_FAILURE(status))
{
delete fmt;
PEG_METHOD_EXIT();
return (dateTimeValue.toString());
}
// convert UnicodeString to char *
char dateTimeBuffer[256];
char *extractedStr = 0;
// Copy the contents of the string into dateTimeBuffer
Uint32 strLen = dateTimeUniStr.extract(0, sizeof(dateTimeBuffer),
dateTimeBuffer);
// There is not enough space in dateTimeBuffer
if (strLen > sizeof(dateTimeBuffer))
{
extractedStr = new char[strLen + 1];
strLen = dateTimeUniStr.extract(0, strLen + 1, extractedStr);
}
else
{
extractedStr = dateTimeBuffer;
}
//.........这里部分代码省略.........