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


Java TimeZone.getDisplayName方法代碼示例

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


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

示例1: getTimeZoneDisplay

import java.util.TimeZone; //導入方法依賴的package包/類
/**
 * <p>Gets the time zone display name, using a cache for performance.</p>
 * 
 * @param tz  the zone to query
 * @param daylight  true if daylight savings
 * @param style  the style to use <code>TimeZone.LONG</code>
 *  or <code>TimeZone.SHORT</code>
 * @param locale  the locale to use
 * @return the textual name of the time zone
 */
static synchronized String getTimeZoneDisplay(TimeZone tz, boolean daylight, int style, Locale locale) {
    Object key = new TimeZoneDisplayKey(tz, daylight, style, locale);
    String value = (String) cTimeZoneDisplayCache.get(key);
    if (value == null) {
        // This is a very slow call, so cache the results.
        value = tz.getDisplayName(daylight, style, locale);
        cTimeZoneDisplayCache.put(key, value);
    }
    return value;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:21,代碼來源:FastDateFormat.java

示例2: getTimeZoneDisplay

import java.util.TimeZone; //導入方法依賴的package包/類
/**
 * <p>Gets the time zone display name, using a cache for performance.</p>
 *
 * @param tz       the zone to query
 * @param daylight true if daylight savings
 * @param style    the style to use {@code TimeZone.LONG} or {@code TimeZone.SHORT}
 * @param locale   the locale to use
 * @return the textual name of the time zone
 */
static String getTimeZoneDisplay(final TimeZone tz, final boolean daylight, final int style, final Locale locale) {
    final TimeZoneDisplayKey key = new TimeZoneDisplayKey(tz, daylight, style, locale);
    String value = cTimeZoneDisplayCache.get(key);
    if (value == null) {
        // This is a very slow call, so cache the results.
        value = tz.getDisplayName(daylight, style, locale);
        final String prior = cTimeZoneDisplayCache.putIfAbsent(key, value);
        if (prior != null) {
            value = prior;
        }
    }
    return value;
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:23,代碼來源:FastDatePrinter.java

示例3: getCurrentTimeZone

import java.util.TimeZone; //導入方法依賴的package包/類
/**
 * Gets the time zone of the current time zone
 *
 * @return time zone String GMT+05:45
 */
public static String getCurrentTimeZone() {
    TimeZone tz = TimeZone.getDefault();
    String strTz = tz.getDisplayName(false, TimeZone.SHORT);
    System.out.println("getCurrentTimeZone: " + strTz);
    return strTz;
}
 
開發者ID:Jusenr,項目名稱:androidtools,代碼行數:12,代碼來源:DateUtils.java

示例4: getTimeZone

import java.util.TimeZone; //導入方法依賴的package包/類
public static int getTimeZone() {

        TimeZone tz = TimeZone.getDefault();
        String displayName = tz.getDisplayName();
        int dstSavings = tz.getDSTSavings();
        String id = tz.getID();
        String displayName2 = tz.getDisplayName(false, TimeZone.SHORT);

        return 1;
    }
 
開發者ID:zeng3234,項目名稱:GrowingProject,代碼行數:11,代碼來源:DateUtils.java

示例5: createTimezoneDTO

import java.util.TimeZone; //導入方法依賴的package包/類
/**
    * Returns new <code>Timezone</code> object with populated values.
    *
    * @param timeZone
    * @param selected
    * @return
    */
   public static TimezoneDTO createTimezoneDTO(TimeZone timeZone, boolean selected) {
TimezoneDTO timezoneDTO = new TimezoneDTO();
timezoneDTO.timeZoneId = timeZone.getID();
int timeZoneRawOffset = timeZone.getRawOffset();
timezoneDTO.rawOffset = new Date(Math.abs(timeZoneRawOffset));
timezoneDTO.isRawOffsetNegative = timeZoneRawOffset < 0;
timezoneDTO.dstOffset = timeZone.getDSTSavings() / 60000;
timezoneDTO.displayName = timeZone.getDisplayName();
timezoneDTO.selected = selected;
return timezoneDTO;
   }
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:19,代碼來源:TimezoneDTO.java

示例6: handle

import java.util.TimeZone; //導入方法依賴的package包/類
@GET
@Timed
public Response handle(@Context UriInfo uriInfo){
    List<String> location = new ArrayList<>();
    if(uriInfo.getQueryParameters().containsKey("location")) {
        location = uriInfo.getQueryParameters().get("location");
        if (location.size() != 1)
            throwError(BAD_REQUEST.getStatusCode(), "only one location needs to be specified");
    }
    else throwError(BAD_REQUEST.getStatusCode(), "location missing. a location needs to be specified");;
    List<String> timestamps = new ArrayList<>();
    if(uriInfo.getQueryParameters().containsKey("timestamp")) {
        timestamps = uriInfo.getQueryParameters().get("timestamp");
        if (timestamps.size() != 1)
            throwError(BAD_REQUEST.getStatusCode(), "only one unix timestamp needs to be specified");
    }
    else throwError(BAD_REQUEST.getStatusCode(), "timestamp missing. unix timestamp needs to be specified");
    Locale locale = Locale.forLanguageTag("en");
    if(uriInfo.getQueryParameters().containsKey("language")) {
        List<String> languages = uriInfo.getQueryParameters().get("language");
        if (languages.size() != 1) throwError(BAD_REQUEST.getStatusCode(), "only one language needs to be specified");
        locale = Locale.forLanguageTag(languages.get(0));
    }

    String[] locationTokens = location.get(0).split(",");
    double lat = Double.parseDouble(locationTokens[0]);
    double lon = Double.parseDouble(locationTokens[1]);
    long timestamp = Long.parseLong(timestamps.get(0));
    String timeZoneId = getTimeZone(lat,lon);
    TimeZone timeZone = TimeZone.getTimeZone(timeZoneId);
    OffsetDateTime localTime = getLocalTime(timeZone,timestamp);
    com.graphhopper.timezone.api.TimeZone timeZoneResponse = new com.graphhopper.timezone.api.TimeZone(timeZoneId, new LocalTime(localTime,locale), timeZone.getDisplayName(locale));
    return Response.status(Response.Status.OK).entity(timeZoneResponse).build();

}
 
開發者ID:graphhopper,項目名稱:timezone,代碼行數:36,代碼來源:TimeZoneService.java

示例7: test_printText

import java.util.TimeZone; //導入方法依賴的package包/類
public void test_printText() {
    Random r = RandomFactory.getRandom();
    int N = 8;
    Locale[] locales = Locale.getAvailableLocales();
    Set<String> zids = ZoneRulesProvider.getAvailableZoneIds();
    ZonedDateTime zdt = ZonedDateTime.now();

    //System.out.printf("locale==%d, timezone=%d%n", locales.length, zids.size());
    while (N-- > 0) {
        zdt = zdt.withDayOfYear(r.nextInt(365) + 1)
                 .with(ChronoField.SECOND_OF_DAY, r.nextInt(86400));
        for (String zid : zids) {
            if (zid.equals("ROC") || zid.startsWith("Etc/GMT")) {
                continue;      // TBD: match jdk behavior?
            }
            zdt = zdt.withZoneSameLocal(ZoneId.of(zid));
            TimeZone tz = TimeZone.getTimeZone(zid);
            boolean isDST = tz.inDaylightTime(new Date(zdt.toInstant().toEpochMilli()));
            for (Locale locale : locales) {
                String longDisplayName = tz.getDisplayName(isDST, TimeZone.LONG, locale);
                String shortDisplayName = tz.getDisplayName(isDST, TimeZone.SHORT, locale);
                if ((longDisplayName.startsWith("GMT+") && shortDisplayName.startsWith("GMT+"))
                        || (longDisplayName.startsWith("GMT-") && shortDisplayName.startsWith("GMT-"))) {
                    printText(locale, zdt, TextStyle.FULL, tz, tz.getID());
                    printText(locale, zdt, TextStyle.SHORT, tz, tz.getID());
                    continue;
                }
                printText(locale, zdt, TextStyle.FULL, tz,
                        tz.getDisplayName(isDST, TimeZone.LONG, locale));
                printText(locale, zdt, TextStyle.SHORT, tz,
                        tz.getDisplayName(isDST, TimeZone.SHORT, locale));
            }
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:36,代碼來源:TestZoneTextPrinterParser.java

示例8: checkTimeZone

import java.util.TimeZone; //導入方法依賴的package包/類
private static void checkTimeZone(String timeZoneID, String expected) {
    TimeZone timeZone = TimeZone.getTimeZone(timeZoneID);
    String actual = timeZone.getDisplayName();
    if (!expected.equals(actual)) {
        throw new RuntimeException();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:HongKong.java

示例9: main

import java.util.TimeZone; //導入方法依賴的package包/類
public static void main(String[] args) {
    TimeZone UTC = TimeZone.getTimeZone("UTC");
    TimeZone initTz = TimeZone.getDefault();

    List<String> errors = new ArrayList<>();
    try {
        TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
        for (Locale locale : DateFormat.getAvailableLocales()) {
            // exclude any locales which localize "UTC".
            String utc = UTC.getDisplayName(false, SHORT, locale);
            if (!"UTC".equals(utc)) {
                System.out.println("Skipping " + locale + " due to localized UTC name: " + utc);
                continue;
            }
            SimpleDateFormat fmt = new SimpleDateFormat("z", locale);
            try {
                Date date = fmt.parse("UTC");
                // Parsed one may not exactly be UTC. Universal, UCT, etc. are equivalents.
                if (!fmt.getTimeZone().getID().matches("(Etc/)?(UTC|Universal|UCT|Zulu)")) {
                    errors.add("timezone: " + fmt.getTimeZone().getID()
                               + ", locale: " + locale);
                }
            } catch (ParseException e) {
                errors.add("parse exception: " + e + ", locale: " + locale);
            }
        }
    } finally {
        // Restore the default time zone
        TimeZone.setDefault(initTz);
    }

    if (!errors.isEmpty()) {
        System.out.println("Got unexpected results:");
        for (String s : errors) {
            System.out.println("    " + s);
        }
        throw new RuntimeException("Test failed.");
    } else {
        System.out.println("Test passed.");
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:42,代碼來源:Bug8141243.java


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