当前位置: 首页>>代码示例>>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;未经允许,请勿转载。