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


Java TextStyle类代码示例

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


TextStyle类属于java.time.format包,在下文中一共展示了TextStyle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test_standaloneNormal

import java.time.format.TextStyle; //导入依赖的package包/类
@Test
public void test_standaloneNormal() {
    assertEquals(TextStyle.FULL, TextStyle.FULL_STANDALONE.asNormal());
    assertEquals(TextStyle.SHORT, TextStyle.SHORT.asNormal());
    assertEquals(TextStyle.NARROW, TextStyle.NARROW.asNormal());

    assertEquals(TextStyle.FULL_STANDALONE, TextStyle.FULL_STANDALONE.asStandalone());
    assertEquals(TextStyle.SHORT_STANDALONE, TextStyle.SHORT.asStandalone());
    assertEquals(TextStyle.NARROW_STANDALONE, TextStyle.NARROW.asStandalone());

    assertTrue(TextStyle.FULL_STANDALONE.isStandalone());
    assertTrue(TextStyle.SHORT_STANDALONE.isStandalone());
    assertTrue(TextStyle.NARROW_STANDALONE.isStandalone());

    assertTrue(!TextStyle.FULL.isStandalone());
    assertTrue(!TextStyle.SHORT.isStandalone());
    assertTrue(!TextStyle.NARROW.isStandalone());
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:TCKTextStyle.java

示例2: test_ParseText

import java.time.format.TextStyle; //导入依赖的package包/类
@Test(dataProvider="preferredZones")
public void test_ParseText(String expected, String text, Set<ZoneId> preferred, Locale locale, TextStyle style) {
    DateTimeFormatter fmt = new DateTimeFormatterBuilder().appendZoneText(style, preferred)
                                                          .toFormatter(locale)
                                                          .withDecimalStyle(DecimalStyle.of(locale));

    String ret = fmt.parse(text, TemporalQueries.zone()).getId();

    System.out.printf("[%-5s %s] %24s -> %s(%s)%n",
                      locale.toString(),
                      style == TextStyle.FULL ? " full" :"short",
                      text, ret, expected);

    assertEquals(ret, expected);

}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:TestZoneTextPrinterParser.java

示例3: data_preferredZones

import java.time.format.TextStyle; //导入依赖的package包/类
@DataProvider(name="preferredZones")
    Object[][] data_preferredZones() {
        return new Object[][] {
            {"America/New_York", "Eastern Standard Time", none,      Locale.ENGLISH, TextStyle.FULL},
//          {"EST",              "Eastern Standard Time", preferred, Locale.ENGLISH, TextStyle.FULL},
            {"Europe/Paris",     "Central European Time", none,      Locale.ENGLISH, TextStyle.FULL},
            {"CET",              "Central European Time", preferred, Locale.ENGLISH, TextStyle.FULL},
            {"Asia/Shanghai",    "China Standard Time",   none,      Locale.ENGLISH, TextStyle.FULL},
            {"Asia/Taipei",      "China Standard Time",   preferred, Locale.ENGLISH, TextStyle.FULL},
            {"America/Chicago",  "CST",                   none,      Locale.ENGLISH, TextStyle.SHORT},
            {"Asia/Taipei",      "CST",                   preferred, Locale.ENGLISH, TextStyle.SHORT},
            {"Australia/South",  "ACST",                  preferred_s, Locale.ENGLISH, TextStyle.SHORT},
            {"America/Chicago",  "CDT",                   none,        Locale.ENGLISH, TextStyle.SHORT},
            {"Asia/Shanghai",    "CDT",                   preferred_s, Locale.ENGLISH, TextStyle.SHORT},
       };
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:TestZoneTextPrinterParser.java

示例4: parseText

import java.time.format.TextStyle; //导入依赖的package包/类
private void parseText(Set<String> zids, Locale locale, TextStyle style, boolean ci) {
    System.out.println("---------------------------------------");
    DateTimeFormatter fmt = getFormatter(locale, style, ci);
    for (String[] names : new DateFormatSymbols(locale).getZoneStrings()) {
        if (!zids.contains(names[0])) {
            continue;
        }
        String zid = names[0];
        String expected = ZoneName.toZid(zid, locale);

        parse(fmt, zid, expected, zid, locale, style, ci);
        int i = style == TextStyle.FULL ? 1 : 2;
        for (; i < names.length; i += 2) {
            parse(fmt, zid, expected, names[i], locale, style, ci);
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:TestZoneTextPrinterParser.java

示例5: test3

import java.time.format.TextStyle; //导入依赖的package包/类
void test3() {
    final String[] TZNAMES = {
        LATIME, PST, PST8PDT, US_PACIFIC,
        TOKYOTIME, JST, JAPAN,
    };
    for (String tzname : TZNAMES) {
        TimeZone tz = TimeZone.getTimeZone(tzname);
        for (int style : new int[] { TimeZone.LONG, TimeZone.SHORT }) {
            String osakaStd = tz.getDisplayName(false, style, OSAKA);
            if (osakaStd != null) {
                String generic = tz.toZoneId().getDisplayName(
                        style == TimeZone.LONG ? TextStyle.FULL : TextStyle.SHORT,
                        GENERIC);
                String expected = "Generic " + osakaStd;
                if (!expected.equals(generic)) {
                    throw new RuntimeException("Wrong generic name: got=\"" + generic
                                               + "\", expected=\"" + expected + "\"");
                }
            }
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:TimeZoneNameProviderTest.java

示例6: test_parseStandaloneText

import java.time.format.TextStyle; //导入依赖的package包/类
@Test(dataProvider="parseStandaloneText")
public void test_parseStandaloneText(Locale locale, TemporalField field, TextStyle style, int expectedValue, String input) {
    DateTimeFormatter formatter = getFormatter(field, style).withLocale(locale);
    ParsePosition pos = new ParsePosition(0);
    assertEquals(formatter.parseUnresolved(input, pos).getLong(field), (long) expectedValue);
    assertEquals(pos.getIndex(), input.length());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:TestTextParserWithLocale.java

示例7: test_pattern_String

import java.time.format.TextStyle; //导入依赖的package包/类
@Test
public void test_pattern_String() {
    DateTimeFormatter test = DateTimeFormatter.ofPattern("d MMM yyyy");
    Locale fmtLocale = Locale.getDefault(Locale.Category.FORMAT);
    assertEquals(test.format(LocalDate.of(2012, 6, 30)), "30 " +
            Month.JUNE.getDisplayName(TextStyle.SHORT, fmtLocale) + " 2012");
    assertEquals(test.getLocale(), fmtLocale, "Locale.Category.FORMAT");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:TCKDateTimeFormatters.java

示例8: factory_of_String_offsetBasedValid_prefixGMT

import java.time.format.TextStyle; //导入依赖的package包/类
@Test(dataProvider="offsetBasedValidPrefix")
public void factory_of_String_offsetBasedValid_prefixGMT(String input, String id, String offsetId) {
    ZoneId test = ZoneId.of("GMT" + input);
    assertEquals(test.getId(), "GMT" + id);
    assertEquals(test.getRules(), ZoneOffset.of(offsetId).getRules());
    assertEquals(test.normalized(), ZoneOffset.of(offsetId));
    assertEquals(test.getDisplayName(TextStyle.FULL, Locale.UK), displayName("GMT" + id));
    assertEquals(test.getRules().isFixedOffset(), true);
    assertEquals(test.getRules().getOffset(Instant.EPOCH), ZoneOffset.of(offsetId));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:TCKZoneId.java

示例9: serialize

import java.time.format.TextStyle; //导入依赖的package包/类
@Override
public void serialize(LocalDate localDate, JsonGenerator jsonGenerator,
        SerializerProvider serializerProvider) throws IOException {
    jsonGenerator.writeStartObject();

    jsonGenerator.writeStringField("text", localDate.toString()); // "2017-06-25"
    jsonGenerator.writeNumberField("year", localDate.getYear());
    jsonGenerator.writeNumberField("month", localDate.getMonthValue());
    jsonGenerator.writeNumberField("day", localDate.getDayOfMonth());
    jsonGenerator.writeStringField("dayOfWeek",
            localDate.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.US)); // "Sunday"
    jsonGenerator.writeNumberField("dayOfYear", localDate.getDayOfYear()); // 176

    jsonGenerator.writeEndObject();
}
 
开发者ID:robinhowlett,项目名称:chart-parser,代码行数:16,代码来源:SimpleLocalDateSerializer.java

示例10: createSingleDayHeader

import java.time.format.TextStyle; //导入依赖的package包/类
public Node createSingleDayHeader(LocalDate date) {
    final Label lblWeekday = new Label(date.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.getDefault()));
    lblWeekday.getStyleClass().add("header-weekday");
    final Label lblDate = new Label(DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).format(date));
    lblDate.getStyleClass().add("header-date");
    VBox container = new VBox(lblDate, lblWeekday);
    container.getStyleClass().add("header-container");
    if(date.equals(LocalDate.now())) {
        container.getStyleClass().add("header-container-today");
    }
    container.setAlignment(Pos.TOP_CENTER);
    return container;
}
 
开发者ID:Jibbow,项目名称:FastisFX,代码行数:14,代码来源:WeekViewRenderer.java

示例11: test_parse_strict_caseInsensitive_parseLower

import java.time.format.TextStyle; //导入依赖的package包/类
@Test(dataProvider="parseText")
public void test_parse_strict_caseInsensitive_parseLower(TemporalField field, TextStyle style, int value, String input) throws Exception {
    setCaseSensitive(false);
    ParsePosition pos = new ParsePosition(0);
    assertEquals(getFormatter(field, style).parseUnresolved(input.toLowerCase(Locale.ROOT), pos).getLong(field), (long) value);
    assertEquals(pos.getIndex(), input.length());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:TestTextParser.java

示例12: test_constant_UTC

import java.time.format.TextStyle; //导入依赖的package包/类
public void test_constant_UTC() {
    ZoneId test = ZoneOffset.UTC;
    assertEquals(test.getId(), "Z");
    assertEquals(test.getDisplayName(TextStyle.FULL, Locale.UK), "Z");
    assertEquals(test.getRules().isFixedOffset(), true);
    assertEquals(test.getRules().getOffset(Instant.ofEpochSecond(0L)), ZoneOffset.UTC);
    checkOffset(test.getRules(), createLDT(2008, 6, 30), ZoneOffset.UTC, 1);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:TestZoneId.java

示例13: factory_of_String_offsetBasedValid_noPrefix

import java.time.format.TextStyle; //导入依赖的package包/类
@Test(dataProvider="offsetBasedValid")
public void factory_of_String_offsetBasedValid_noPrefix(String input, String id) {
    ZoneId test = ZoneId.of(input);
    assertEquals(test.getId(), id);
    assertEquals(test, ZoneOffset.of(id));
    assertEquals(test.normalized(), ZoneOffset.of(id));
    assertEquals(test.getDisplayName(TextStyle.FULL, Locale.UK), id);
    assertEquals(test.getRules().isFixedOffset(), true);
    assertEquals(test.getRules().getOffset(Instant.EPOCH), ZoneOffset.of(id));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:TCKZoneId.java

示例14: test_parse_midStr

import java.time.format.TextStyle; //导入依赖的package包/类
public void test_parse_midStr() throws Exception {
    ParsePosition pos = new ParsePosition(3);
    assertEquals(getFormatter(DAY_OF_WEEK, TextStyle.FULL)
                 .parseUnresolved("XxxMondayXxx", pos)
                 .getLong(DAY_OF_WEEK), 1L);
    assertEquals(pos.getIndex(), 9);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:TestTextParser.java

示例15: LocalTime

import java.time.format.TextStyle; //导入依赖的package包/类
public LocalTime(OffsetDateTime offsetDateTime, Locale locale) {
    offset = offsetDateTime.getOffset().getTotalSeconds();
    year = offsetDateTime.getYear();
    month = offsetDateTime.getMonth().getDisplayName(TextStyle.FULL,locale);
    dayOfMonth = offsetDateTime.getDayOfMonth();
    dayOfWeek = offsetDateTime.getDayOfWeek().getDisplayName(TextStyle.FULL,locale);
    monthValue = offsetDateTime.getMonthValue();
    hour = offsetDateTime.getHour();
    minute = offsetDateTime.getMinute();
    second = offsetDateTime.getSecond();
    nano = offsetDateTime.getNano();
}
 
开发者ID:graphhopper,项目名称:timezone,代码行数:13,代码来源:LocalTime.java


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