本文整理汇总了C++中TimeZone类的典型用法代码示例。如果您正苦于以下问题:C++ TimeZone类的具体用法?C++ TimeZone怎么用?C++ TimeZone使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TimeZone类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: ucal_getDSTSavings
U_CAPI int32_t U_EXPORT2
ucal_getDSTSavings(const UChar* zoneID, UErrorCode* ec) {
int32_t result = 0;
TimeZone* zone = _createTimeZone(zoneID, -1, ec);
if (U_SUCCESS(*ec)) {
SimpleTimeZone* stz = dynamic_cast<SimpleTimeZone*>(zone);
if (stz != NULL) {
result = stz->getDSTSavings();
} else {
// Since there is no getDSTSavings on TimeZone, we use a
// heuristic: Starting with the current time, march
// forwards for one year, looking for DST savings.
// Stepping by weeks is sufficient.
UDate d = Calendar::getNow();
for (int32_t i=0; i<53; ++i, d+=U_MILLIS_PER_DAY*7.0) {
int32_t raw, dst;
zone->getOffset(d, FALSE, raw, dst, *ec);
if (U_FAILURE(*ec)) {
break;
} else if (dst != 0) {
result = dst;
break;
}
}
}
}
delete zone;
return result;
}
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:29,代码来源:ucal.cpp
示例2: TZEnumeration
TZEnumeration(int32_t rawOffset) : map(NULL), len(0), pos(0) {
if (!getOlsonMeta()) {
return;
}
// Allocate more space than we'll need. The end of the array will
// be blank.
map = (int32_t*)uprv_malloc(OLSON_ZONE_COUNT * sizeof(int32_t));
if (map == 0) {
return;
}
uprv_memset(map, 0, sizeof(int32_t) * OLSON_ZONE_COUNT);
UnicodeString s;
for (int32_t i=0; i<OLSON_ZONE_COUNT; ++i) {
if (getID(i)) {
// This is VERY inefficient.
TimeZone* z = TimeZone::createTimeZone(unistr);
// Make sure we get back the ID we wanted (if the ID is
// invalid we get back GMT).
if (z != 0 && z->getID(s) == unistr &&
z->getRawOffset() == rawOffset) {
map[len++] = i;
}
delete z;
}
}
}
开发者ID:flwh,项目名称:Alcatel_OT_985_kernel,代码行数:29,代码来源:timezone.cpp
示例3: ures_initStackObject
TimeZone*
TimeZone::createSystemTimeZone(const UnicodeString& id) {
TimeZone* z = 0;
UErrorCode ec = U_ZERO_ERROR;
UResourceBundle res;
ures_initStackObject(&res);
U_DEBUG_TZ_MSG(("pre-err=%s\n", u_errorName(ec)));
UResourceBundle *top = openOlsonResource(id, res, ec);
U_DEBUG_TZ_MSG(("post-err=%s\n", u_errorName(ec)));
if (U_SUCCESS(ec)) {
z = new OlsonTimeZone(top, &res, ec);
if (z) {
z->setID(id);
} else {
U_DEBUG_TZ_MSG(("cstz: olson time zone failed to initialize - err %s\n", u_errorName(ec)));
}
}
ures_close(&res);
ures_close(top);
if (U_FAILURE(ec)) {
U_DEBUG_TZ_MSG(("cstz: failed to create, err %s\n", u_errorName(ec)));
delete z;
z = 0;
}
return z;
}
开发者ID:flwh,项目名称:Alcatel_OT_985_kernel,代码行数:26,代码来源:timezone.cpp
示例4: failure
void DateFormatRoundTripTest::TestDateFormatRoundTrip()
{
UErrorCode status = U_ZERO_ERROR;
getFieldCal = Calendar::createInstance(status);
failure(status, "Calendar::createInstance");
if(!assertSuccess("trying to construct", status))return;
int32_t locCount = 0;
const Locale *avail = DateFormat::getAvailableLocales(locCount);
logln("DateFormat available locales: %d", locCount);
if(quick) {
SPARSENESS = 18;
logln("Quick mode: only testing SPARSENESS = 18");
}
TimeZone *tz = TimeZone::createDefault();
UnicodeString temp;
logln("Default TimeZone: " + tz->getID(temp));
delete tz;
#ifdef TEST_ONE_LOC // define this to just test ONE locale.
Locale loc(TEST_ONE_LOC);
test(loc);
#if INFINITE
for(;;) {
test(loc);
}
#endif
#else
# if INFINITE
// Special infinite loop test mode for finding hard to reproduce errors
Locale loc = Locale::getDefault();
logln("ENTERING INFINITE TEST LOOP FOR Locale: " + loc.getDisplayName(temp));
for(;;)
test(loc);
# else
test(Locale::getDefault());
#if 1
// installed locales
for (int i=0; i < locCount; ++i) {
test(avail[i]);
}
#endif
#if 1
// special locales
int32_t jCount = CalendarTest::testLocaleCount();
for (int32_t j=0; j < jCount; ++j) {
test(Locale(CalendarTest::testLocaleID(j)));
}
#endif
# endif
#endif
delete getFieldCal;
}
开发者ID:flwh,项目名称:Alcatel_OT_985_kernel,代码行数:60,代码来源:dtfmtrtts.cpp
示例5: getDisplayTimeZoneNative
static jstring getDisplayTimeZoneNative(JNIEnv* env, jclass clazz,
jstring zoneID, jboolean isDST, jint style, jstring localeID) {
// Build TimeZone object
const jchar* idChars = env->GetStringChars(zoneID, NULL);
jint idLength = env->GetStringLength(zoneID);
UnicodeString idString((UChar*)idChars, idLength);
TimeZone* zone = TimeZone::createTimeZone(idString);
env->ReleaseStringChars(zoneID, idChars);
// Build Locale object (can we rely on zero termination of JNI result?)
const char* localeChars = env->GetStringUTFChars(localeID, NULL);
jint localeLength = env->GetStringLength(localeID);
Locale locale = Locale::createFromName(localeChars);
// Try to get the display name of the TimeZone according to the Locale
UnicodeString buffer;
zone->getDisplayName((UBool)isDST, (style == 0 ? TimeZone::SHORT : TimeZone::LONG), locale, buffer);
const UChar* tempChars = buffer.getBuffer();
int tempLength = buffer.length();
jstring result = env->NewString((jchar*)tempChars, tempLength);
env->ReleaseStringUTFChars(localeID, localeChars);
// Clean up everything
delete(zone);
return result;
}
开发者ID:llnull,项目名称:platform_dalvik,代码行数:28,代码来源:ResourceInterface.cpp
示例6: TIMEZONE_Get_display_name
void TIMEZONE_Get_display_name(sLONG_PTR *pResult, PackagePtr pParams)
{
C_TEXT Param1;
C_TEXT Param2;
C_LONGINT returnValue;
Param1.fromParamAtIndex(pParams, 1);
UErrorCode status = U_ZERO_ERROR;
Param1.fromParamAtIndex(pParams, 1);
UnicodeString zoneId = UnicodeString((const UChar *)Param1.getUTF16StringPtr());
TimeZone *zone = TimeZone::createTimeZone(zoneId);
if(zone){
UnicodeString displayName;
zone->getDisplayName (displayName);
DT::setUnicodeString(Param2, displayName);
delete zone;
}else{
status = U_ILLEGAL_ARGUMENT_ERROR;
}
returnValue.setIntValue(status);
Param2.toParamAtIndex(pParams, 2);
returnValue.setReturn(pResult);
}
开发者ID:UNIVERSAL-IT-SYSTEMS,项目名称:4d-plugin-time-and-number,代码行数:32,代码来源:4DPlugin.cpp
示例7: DateTime
//
// Constructor.
//
LocalTime::LocalTime(int32_t ot) :
DateTime(),
rule(&dstnever),
dst(false)
{
TimeZone zone;
this->offset = zone.normalize(ot);
}
开发者ID:coverclock,项目名称:com-diag-desperado,代码行数:11,代码来源:LocalTime.cpp
示例8:
String
EditEventForm::GetTimezoneString(void) const
{
LocaleManager localeManager;
localeManager.Construct();
TimeZone timeZone = localeManager.GetSystemTimeZone();
return timeZone.GetId();
}
开发者ID:minicho,项目名称:TIZEN5-,代码行数:9,代码来源:EditEventForm.cpp
示例9: milspec
const char* TimeStamp::milspec(const LocalTime& lt) {
TimeZone zone;
::snprintf(this->buffer, sizeof(this->buffer),
"%04llu-%3.3s-%02u %02u:%02u:%02u%1.1s",
lt.getYear(), lt.getDate().monthToString(), lt.getDay(),
lt.getHour(), lt.getMinute(), lt.getSecond(),
zone.milspec(lt.getOffset()));
this->buffer[sizeof(this->buffer) - 1] = '\0';
assert(std::strlen(this->buffer) < sizeof(this->buffer));
return this->buffer;
}
开发者ID:coverclock,项目名称:com-diag-desperadito,代码行数:11,代码来源:TimeStamp.cpp
示例10: log
// Log line space is at a premium. It pays to have as high a precision timestamp
// as the underlying platform supports, but no more. Generally about a
// microsecond is the best we can hope for on Linux platforms. But I've used
// vxWorks platforms that had time bases accurate to tens of nanoseconds. So
// consider altering the print format from ".%06u" to ".%09u" and removing the
// "/ 1000" nanosecond divisor.
const char* TimeStamp::log(const LocalTime& lt) {
TimeZone zone;
::snprintf(this->buffer, sizeof(this->buffer),
"%04llu-%02u-%02u %02u:%02u:%02u.%06u%1.1s",
lt.getYear(), lt.getMonth(), lt.getDay(),
lt.getHour(), lt.getMinute(), lt.getSecond(),
lt.getNanosecond() / 1000,
zone.milspec(lt.getOffset()));
this->buffer[sizeof(this->buffer) - 1] = '\0';
assert(std::strlen(this->buffer) < sizeof(this->buffer));
return this->buffer;
}
开发者ID:coverclock,项目名称:com-diag-desperadito,代码行数:18,代码来源:TimeStamp.cpp
示例11: offsetFromUtcToTz
int TimezoneUtils::offsetFromUtcToTz(QDateTime date, QString timezoneId, bool ignoreDstOffset, bool* error)
{
int offset = 0;
UErrorCode errorCode = U_ZERO_ERROR;
// get timezone object
TimeZone* tz = TimeZone::createTimeZone(reinterpret_cast<UChar*>(timezoneId.data()));
if (!tz) {
*error = true;
return 0;
}
UnicodeString name;
tz->getDisplayName(name);
// get offset
// cal takes ownership of tz - tried to delete it and got an error
Calendar* cal = Calendar::createInstance(tz, errorCode);
if (!cal || errorCode > 0) {
*error = true;
return 0;
}
cal->set(date.date().year(), date.date().month(), date.date().day(), date.time().hour(), date.time().minute());
UDate udate = cal->getTime(errorCode);
if (errorCode > 0) {
*error = true;
delete cal;
return 0;
}
UBool isGmt = false;
int32_t rawOffset = 0;
int32_t dstOffset = 0;
tz->getOffset(udate, isGmt, rawOffset, dstOffset, errorCode);
if (errorCode > 0) {
*error = true;
delete cal;
return 0;
}
if (!ignoreDstOffset) {
offset = rawOffset + dstOffset;
} else {
offset = rawOffset;
}
delete cal;
offset /= 1000;
*error = false;
return offset;
}
开发者ID:RonMen,项目名称:BB10-WebWorks-Framework,代码行数:52,代码来源:timezone_utils.cpp
示例12: getDisplayTimeZoneNative
static jstring getDisplayTimeZoneNative(JNIEnv* env, jclass clazz,
jstring zoneId, jboolean isDST, jint style, jstring localeId) {
TimeZone* zone = timeZoneFromId(env, zoneId);
Locale locale = getLocale(env, localeId);
// Try to get the display name of the TimeZone according to the Locale
UnicodeString displayName;
zone->getDisplayName((UBool)isDST, (style == 0 ? TimeZone::SHORT : TimeZone::LONG), locale, displayName);
jstring result = env->NewString(displayName.getBuffer(), displayName.length());
delete zone;
return result;
}
开发者ID:Ar3kkusu,项目名称:android_libcore,代码行数:13,代码来源:Resources.cpp
示例13: AppLog
void
TimeAndPlace::SetSiderialTime(float longitude, float latitude, DateTime* currTime) {
AppLog("Trying to access TimeAndPlace");
TimeAndPlace::SetLongitude(longitude);
AppLog("Trying to access TimeAndPlace 1");
TimeAndPlace::SetLatitude(latitude);
AppLog("Trying to access TimeAndPlace 2");
//TimeZone timeZone(60, L"Europe/London");
LocaleManager localeManager;
localeManager.Construct();
Locale locale = localeManager.GetSystemLocale();
TimeZone timeZone = localeManager.GetSystemTimeZone();
AppLog("Locale code %S", (locale.GetLanguageCodeString().GetPointer()));
AppLog("TimeZone ID is %S", (timeZone.GetId()).GetPointer());
// TimeZone timeZone(TimeZone::GetGmtTimeZone());
AppLog("TP1");
SystemTime::GetCurrentTime(*currTime);
AppLog("TP2");
dateTime = currTime;
AppLog("TP2a");
localDateTime = &(timeZone.UtcTimeToStandardTime(*currTime));
Calendar* calendar;
AppLog("TP3");
calendar = Calendar::CreateInstanceN(timeZone, CALENDAR_GREGORIAN);
AppLog("TP4");
calendar->SetTime(*currTime);
AppLog("TP5");
float hrs = (calendar->GetTimeField(TIME_FIELD_HOUR_OF_DAY))-1;
AppLog("TP6");
float minHrs = calendar->GetTimeField(TIME_FIELD_MINUTE)/60.0;
AppLog("TP7");
float dayFract = (hrs + minHrs)/24.0;
AppLog("TP8");
float dayNum = calendar->GetTimeField(TIME_FIELD_DAY_OF_YEAR);
AppLog("TP9");
float year = calendar->GetTimeField(TIME_FIELD_YEAR);
AppLog("TP10");
double daysSinceJ2000 = -1.5 + dayNum + (year-2000)*365 + (int)((year-2000)/4) + dayFract;
AppLog("TP11");
double slt = 100.46 + 0.985647 * daysSinceJ2000 + longitude + 15*(hrs + minHrs);
AppLog("TP12");
int sltInt = (int)(slt/360);
AppLog("TP13");
float sltHrs = (slt-(360*sltInt))/15;
AppLog("TP14");
SetSiderialTime (sltHrs);
AppLog("TP15");
}
开发者ID:BGCX261,项目名称:zij-bada-svn-to-git,代码行数:51,代码来源:TimeAndPlace.cpp
示例14: createZone
/**
* If the ID supplied to TimeZone is not a valid system ID,
* TimeZone::createTimeZone() will return a GMT zone object. In order
* to detect this error, we check the ID of the returned zone against
* the ID we requested. If they don't match, we fail with an error.
*/
TimeZone* createZone(const UnicodeString& id) {
UnicodeString str;
TimeZone* zone = TimeZone::createTimeZone(id);
if (zone->getID(str) != id) {
delete zone;
printf("Error: TimeZone::createTimeZone(");
uprintf(id);
printf(") returned zone with ID ");
uprintf(str);
printf("\n");
exit(1);
}
return zone;
}
开发者ID:winlibs,项目名称:icu4c,代码行数:20,代码来源:main_1.cpp
示例15: throw
CString DateTime::FormatISO8601(T_enISO8601Format enFormat, bool bBasic, const TimeZone& tz) const throw()
{
CString cszDate;
switch(enFormat)
{
case formatY: return Format(_T("%Y"), tz);
case formatYM: return Format(bBasic ? _T("%Y%m") : _T("%Y-%m"), tz);
case formatYMD: return Format(bBasic ? _T("%Y%m%d") : _T("%Y-%m-%d"), tz);
case formatYMD_HM_Z:
cszDate = Format(bBasic ? _T("%Y%m%dT%H%M") : _T("%Y-%m-%dT%H:%M"), tz);
break;
case formatYMD_HMS_Z:
cszDate = Format(bBasic ? _T("%Y%m%dT%H%M%S") : _T("%Y-%m-%dT%H:%M:%S"), tz);
break;
case formatYMD_HMSF_Z:
{
cszDate = Format(bBasic ? _T("%Y%m%dT%H%M%S") : _T("%Y-%m-%dT%H:%M:%S"), tz);
CString cszFraction;
cszFraction.Format(_T(".%03u"), Millisecond());
cszDate += cszFraction;
}
break;
}
// add timezone
if (tz.StandardName() == _T("UTC"))
cszDate += _T("Z");
else
{
TimeSpan spTimezone = tz.GetUtcOffset(*this);
bool bNegative = spTimezone < TimeSpan(0, 0, 0, 0);
TimeSpan spTimezoneAbs = bNegative ? -spTimezone : spTimezone;
CString cszTimezone;
cszTimezone.Format(bBasic ? _T("%c%02u%02u") : _T("%c%02u:%02u"),
!bNegative ? _T('+') : _T('-'),
spTimezoneAbs.Hours(),
spTimezoneAbs.Minutes());
cszDate += cszTimezone;
}
return cszDate;
}
开发者ID:zengnotes,项目名称:MultiplayerOnlineGame,代码行数:48,代码来源:DateTime.cpp
示例16: ucal_getDefaultTimeZone
U_CAPI int32_t U_EXPORT2
ucal_getDefaultTimeZone(UChar* result, int32_t resultCapacity, UErrorCode* ec) {
int32_t len = 0;
if (ec!=NULL && U_SUCCESS(*ec)) {
TimeZone* zone = TimeZone::createDefault();
if (zone == NULL) {
*ec = U_MEMORY_ALLOCATION_ERROR;
} else {
UnicodeString id;
zone->getID(id);
delete zone;
len = id.extract(result, resultCapacity, *ec);
}
}
return len;
}
开发者ID:venkatarajasekhar,项目名称:Qt,代码行数:16,代码来源:ucal.cpp
示例17: civilian
const char* TimeStamp::civilian(const LocalTime& lt) {
TimeZone zone;
const char* timezone = zone.civilian(lt.getOffset());
char effective[4];
std::strncpy(effective, timezone, sizeof(effective));
if (lt.getDst() && (3 <= std::strlen(effective))) {
effective[1] = 'D';
}
::snprintf(this->buffer, sizeof(this->buffer),
"%04llu-%02u-%02u %02u:%02u:%02u %s",
lt.getYear(), lt.getMonth(), lt.getDay(),
lt.getHour(), lt.getMinute(), lt.getSecond(),
effective);
this->buffer[sizeof(this->buffer) - 1] = '\0';
assert(std::strlen(this->buffer) < sizeof(this->buffer));
return this->buffer;
}
开发者ID:coverclock,项目名称:com-diag-desperadito,代码行数:17,代码来源:TimeStamp.cpp
示例18: loc
/**
* Test to see if DateFormat understands zone equivalency groups. It
* might seem that this should be a DateFormat test, but it's really a
* TimeZone test -- the changes to DateFormat are minor.
*
* We use two known, stable zones that shouldn't change much over time
* -- America/Vancouver and America/Los_Angeles. However, they MAY
* change at some point -- if that happens, replace them with any two
* zones in an equivalency group where one zone has localized name
* data, and the other doesn't, in some locale.
*/
void TimeZoneRegressionTest::TestJ449() {
UErrorCode status = U_ZERO_ERROR;
UnicodeString str;
// Modify the following three as necessary. The two IDs must
// specify two zones in the same equivalency group. One must have
// locale data in 'loc'; the other must not.
const char* idWithLocaleData = "America/Los_Angeles";
const char* idWithoutLocaleData = "US/Pacific";
const Locale loc("en", "", "");
TimeZone *zoneWith = TimeZone::createTimeZone(idWithLocaleData);
TimeZone *zoneWithout = TimeZone::createTimeZone(idWithoutLocaleData);
// Make sure we got valid zones
if (zoneWith->getID(str) != UnicodeString(idWithLocaleData) ||
zoneWithout->getID(str) != UnicodeString(idWithoutLocaleData)) {
dataerrln(UnicodeString("Fail: Unable to create zones - wanted ") + idWithLocaleData + ", got " + zoneWith->getID(str) + ", and wanted " + idWithoutLocaleData + " but got " + zoneWithout->getID(str));
} else {
GregorianCalendar calWith(*zoneWith, status);
GregorianCalendar calWithout(*zoneWithout, status);
SimpleDateFormat fmt("MMM d yyyy hh:mm a zzz", loc, status);
if (U_FAILURE(status)) {
errln("Fail: Unable to create GregorianCalendar/SimpleDateFormat");
} else {
UDate date = 0;
UnicodeString strWith, strWithout;
fmt.setCalendar(calWith);
fmt.format(date, strWith);
fmt.setCalendar(calWithout);
fmt.format(date, strWithout);
if (strWith == strWithout) {
logln((UnicodeString)"Ok: " + idWithLocaleData + " -> " +
strWith + "; " + idWithoutLocaleData + " -> " +
strWithout);
} else {
errln((UnicodeString)"FAIL: " + idWithLocaleData + " -> " +
strWith + "; " + idWithoutLocaleData + " -> " +
strWithout);
}
}
}
delete zoneWith;
delete zoneWithout;
}
开发者ID:0omega,项目名称:platform_external_icu4c,代码行数:56,代码来源:tzregts.cpp
示例19: TIMEZONE_Get_default
void TIMEZONE_Get_default(sLONG_PTR *pResult, PackagePtr pParams)
{
C_TEXT returnValue;
TimeZone *defaultZone = TimeZone::createDefault();
if(defaultZone){
UnicodeString zoneId;
defaultZone->getID(zoneId);
DT::setUnicodeString(returnValue, zoneId);
delete defaultZone;
}
returnValue.setReturn(pResult);
}
开发者ID:UNIVERSAL-IT-SYSTEMS,项目名称:4d-plugin-time-and-number,代码行数:18,代码来源:4DPlugin.cpp
示例20: getCanonicalCLDRID
const UChar* U_EXPORT2
ZoneMeta::getCanonicalCLDRID(const TimeZone& tz) {
if (dynamic_cast<const OlsonTimeZone *>(&tz) != NULL) {
// short cut for OlsonTimeZone
const OlsonTimeZone *otz = (const OlsonTimeZone*)&tz;
return otz->getCanonicalID();
}
UErrorCode status = U_ZERO_ERROR;
UnicodeString tzID;
return getCanonicalCLDRID(tz.getID(tzID), status);
}
开发者ID:basti1302,项目名称:node,代码行数:11,代码来源:zonemeta.cpp
注:本文中的TimeZone类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论