当前位置: 首页>>代码示例>>C++>>正文


C++ TimeZone类代码示例

本文整理汇总了C++中TimeZone的典型用法代码示例。如果您正苦于以下问题:C++ TimeZone类的具体用法?C++ TimeZone怎么用?C++ TimeZone使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了TimeZone类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的TimeZone类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。