當前位置: 首頁>>代碼示例>>Java>>正文


Java XMLGregorianCalendar.setTimezone方法代碼示例

本文整理匯總了Java中javax.xml.datatype.XMLGregorianCalendar.setTimezone方法的典型用法代碼示例。如果您正苦於以下問題:Java XMLGregorianCalendar.setTimezone方法的具體用法?Java XMLGregorianCalendar.setTimezone怎麽用?Java XMLGregorianCalendar.setTimezone使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.xml.datatype.XMLGregorianCalendar的用法示例。


在下文中一共展示了XMLGregorianCalendar.setTimezone方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: normalize

import javax.xml.datatype.XMLGregorianCalendar; //導入方法依賴的package包/類
/**
 * <p>Normalize this instance to UTC.</p>
 *
 * <p>2000-03-04T23:00:00+03:00 normalizes to 2000-03-04T20:00:00Z</p>
 * <p>Implements W3C XML Schema Part 2, Section 3.2.7.3 (A).</p>
 */
public XMLGregorianCalendar normalize() {

    XMLGregorianCalendar normalized = normalizeToTimezone(timezone);

    // if timezone was undefined, leave it undefined
    if (getTimezone() == DatatypeConstants.FIELD_UNDEFINED) {
        normalized.setTimezone(DatatypeConstants.FIELD_UNDEFINED);
    }

    // if milliseconds was undefined, leave it undefined
    if (getMillisecond() == DatatypeConstants.FIELD_UNDEFINED) {
        normalized.setMillisecond(DatatypeConstants.FIELD_UNDEFINED);
    }

    return normalized;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:23,代碼來源:XMLGregorianCalendarImpl.java

示例2: normalizeToTimezone

import javax.xml.datatype.XMLGregorianCalendar; //導入方法依賴的package包/類
/**
     * <p>Normalize this instance to UTC.</p>
     *
     * <p>2000-03-04T23:00:00+03:00 normalizes to 2000-03-04T20:00:00Z</p>
     * <p>Implements W3C XML Schema Part 2, Section 3.2.7.3 (A).</p>
     */
private XMLGregorianCalendar normalizeToTimezone(int timezone) {

    int minutes = timezone;
    XMLGregorianCalendar result = (XMLGregorianCalendar) this.clone();

    // normalizing to UTC time negates the timezone offset before
    // addition.
    minutes = -minutes;
    Duration d = new DurationImpl(minutes >= 0, // isPositive
            0, //years
            0, //months
            0, //days
            0, //hours
            minutes < 0 ? -minutes : minutes, // absolute
            0  //seconds
    );
    result.add(d);

    // set to zulu UTC time.
    result.setTimezone(0);
    return result;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:29,代碼來源:XMLGregorianCalendarImpl.java

示例3: test

import javax.xml.datatype.XMLGregorianCalendar; //導入方法依賴的package包/類
private static void test(int offsetMinutes)
        throws DatatypeConfigurationException {
    XMLGregorianCalendar calendar = DatatypeFactory.newInstance().
            newXMLGregorianCalendar();
    calendar.setTimezone(60 + offsetMinutes);
    TimeZone timeZone = calendar.getTimeZone(DatatypeConstants.FIELD_UNDEFINED);
    String expected = (offsetMinutes < 10 ? "GMT+01:0" : "GMT+01:")
            + offsetMinutes;
    if (!timeZone.getID().equals(expected)) {
        throw new RuntimeException("Test failed: expected timezone: " +
                expected + " Actual: " + timeZone.getID());
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:14,代碼來源:TestXMLGregorianCalendarTimeZone.java


注:本文中的javax.xml.datatype.XMLGregorianCalendar.setTimezone方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。