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


Java FormatStyle类代码示例

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


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

示例1: main

import java.time.format.FormatStyle; //导入依赖的package包/类
public static void main(String[] args) {
    DateTimeFormatter formatter1 = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM);
    DateTimeFormatter formatter2 = DateTimeFormatter.ofLocalizedTime(FormatStyle.FULL);
    DateTimeFormatter formatter3 = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG);
    DateTimeFormatter formatter4 = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.SHORT);

    DateTimeFormatter formatter5 = DateTimeFormatter.BASIC_ISO_DATE;

    // 2057-08-11
    DateTimeFormatter isoLocalDate = DateTimeFormatter.ISO_LOCAL_DATE;
    DateTimeFormatter isoDate = DateTimeFormatter.ISO_DATE;

    // 14:30:15.312
    DateTimeFormatter isoTime = DateTimeFormatter.ISO_TIME;
    DateTimeFormatter isoLocalTime = DateTimeFormatter.ISO_LOCAL_TIME;

    // 2050-08-11T14:30:15.312
    DateTimeFormatter isoDateTime = DateTimeFormatter.ISO_DATE_TIME;
    DateTimeFormatter isoLocaDateTime = DateTimeFormatter.ISO_LOCAL_DATE_TIME;


}
 
开发者ID:huby,项目名称:java-se8-oca-study-guide,代码行数:23,代码来源:Main.java

示例2: updateList

import java.time.format.FormatStyle; //导入依赖的package包/类
private void updateList(String reason) {
    if (LoggingDomain.VIEW.isLoggable(Level.FINE)) {
        LoggingDomain.VIEW.fine("updating list inside agenda view, reason = " + reason);
    }

    Map<LocalDate, List<Entry<?>>> dataMap = new HashMap<>();
    dataLoader.loadEntries(dataMap);
    List<AgendaEntry> listEntries = new ArrayList<>();
    for (LocalDate date : dataMap.keySet()) {
        AgendaEntry listViewEntry = new AgendaEntry(date);
        for (Entry<?> entry : dataMap.get(date)) {
            listViewEntry.getEntries().add(entry);
        }
        listEntries.add(listViewEntry);
    }

    Collections.sort(listEntries);
    listView.getItems().setAll(listEntries);

    DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG);
    String startTime = formatter.format(getLoadStartDate());
    String endTime = formatter.format(getLoadEndDate());

    statusLabel.setText(MessageFormat.format(Messages.getString("AgendaViewSkin.AGENDA_TIME_RANGE"), startTime, endTime)); //$NON-NLS-1$
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:26,代码来源:AgendaViewSkin.java

示例3: data_date

import java.time.format.FormatStyle; //导入依赖的package包/类
@DataProvider(name="date")
Object[][] data_date() {
    return new Object[][] {
            {LocalDate.of(2012, 6, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.UK},
            {LocalDate.of(2012, 6, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.US},
            {LocalDate.of(2012, 6, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.FRANCE},
            {LocalDate.of(2012, 6, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.JAPAN},

            {LocalDate.of(2012, 6, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.UK},
            {LocalDate.of(2012, 6, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.US},
            {LocalDate.of(2012, 6, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.FRANCE},
            {LocalDate.of(2012, 6, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.JAPAN},

            {LocalDate.of(2012, 6, 30), FormatStyle.LONG, DateFormat.LONG, Locale.UK},
            {LocalDate.of(2012, 6, 30), FormatStyle.LONG, DateFormat.LONG, Locale.US},
            {LocalDate.of(2012, 6, 30), FormatStyle.LONG, DateFormat.LONG, Locale.FRANCE},
            {LocalDate.of(2012, 6, 30), FormatStyle.LONG, DateFormat.LONG, Locale.JAPAN},

            {LocalDate.of(2012, 6, 30), FormatStyle.FULL, DateFormat.FULL, Locale.UK},
            {LocalDate.of(2012, 6, 30), FormatStyle.FULL, DateFormat.FULL, Locale.US},
            {LocalDate.of(2012, 6, 30), FormatStyle.FULL, DateFormat.FULL, Locale.FRANCE},
            {LocalDate.of(2012, 6, 30), FormatStyle.FULL, DateFormat.FULL, Locale.JAPAN},
    };
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:25,代码来源:TCKLocalizedPrinterParser.java

示例4: data_time

import java.time.format.FormatStyle; //导入依赖的package包/类
@DataProvider(name="time")
    Object[][] data_time() {
        return new Object[][] {
                {LocalTime.of(11, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.UK},
                {LocalTime.of(11, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.US},
                {LocalTime.of(11, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.FRANCE},
                {LocalTime.of(11, 30), FormatStyle.SHORT, DateFormat.SHORT, Locale.JAPAN},

                {LocalTime.of(11, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.UK},
                {LocalTime.of(11, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.US},
                {LocalTime.of(11, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.FRANCE},
                {LocalTime.of(11, 30), FormatStyle.MEDIUM, DateFormat.MEDIUM, Locale.JAPAN},

                // these localized patterns include "z" which isn't available from LocalTime
//                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.UK},
//                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.US},
//                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.FRANCE},
//                {LocalTime.of(11, 30), FormatStyle.LONG, DateFormat.LONG, Locale.JAPAN},
//
//                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.UK},
//                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.US},
//                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.FRANCE},
//                {LocalTime.of(11, 30), FormatStyle.FULL, DateFormat.FULL, Locale.JAPAN},
        };
    }
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:26,代码来源:TCKLocalizedPrinterParser.java

示例5: localizedDateTimePatterns

import java.time.format.FormatStyle; //导入依赖的package包/类
@DataProvider(name="localePatterns")
Object[][] localizedDateTimePatterns() {
    return new Object[][] {
        {FormatStyle.FULL, FormatStyle.FULL, IsoChronology.INSTANCE, Locale.US, "EEEE, MMMM d, y 'at' h:mm:ss a zzzz"},
        {FormatStyle.LONG, FormatStyle.LONG, IsoChronology.INSTANCE, Locale.US, "MMMM d, y 'at' h:mm:ss a z"},
        {FormatStyle.MEDIUM, FormatStyle.MEDIUM, IsoChronology.INSTANCE, Locale.US, "MMM d, y, h:mm:ss a"},
        {FormatStyle.SHORT, FormatStyle.SHORT, IsoChronology.INSTANCE, Locale.US, "M/d/yy, h:mm a"},
        {FormatStyle.FULL, null, IsoChronology.INSTANCE, Locale.US, "EEEE, MMMM d, y"},
        {FormatStyle.LONG, null, IsoChronology.INSTANCE, Locale.US, "MMMM d, y"},
        {FormatStyle.MEDIUM, null, IsoChronology.INSTANCE, Locale.US, "MMM d, y"},
        {FormatStyle.SHORT, null, IsoChronology.INSTANCE, Locale.US, "M/d/yy"},
        {null, FormatStyle.FULL, IsoChronology.INSTANCE, Locale.US, "h:mm:ss a zzzz"},
        {null, FormatStyle.LONG, IsoChronology.INSTANCE, Locale.US, "h:mm:ss a z"},
        {null, FormatStyle.MEDIUM, IsoChronology.INSTANCE, Locale.US, "h:mm:ss a"},
        {null, FormatStyle.SHORT, IsoChronology.INSTANCE, Locale.US, "h:mm a"},
    };
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:TestDateTimeFormatterBuilder.java

示例6: localDate

import java.time.format.FormatStyle; //导入依赖的package包/类
public static void localDate() {

        LocalDate now = LocalDate.now();
        LocalDate plus = now.plus(1, ChronoUnit.DAYS);
        LocalDate minus = now.minusDays(1);

        System.out.println(now); //2017-09-20
        System.out.println(plus); //2017-09-21
        System.out.println(minus); //2017-09-19

        LocalDate customDate = LocalDate.of(2017, Month.SEPTEMBER, 20);
        DayOfWeek dayOfWeek = customDate.getDayOfWeek();
        System.out.println(dayOfWeek); //WEDNESDAY 星期三

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter
                .ofLocalizedDate(FormatStyle.MEDIUM)
                .withLocale(Locale.CHINA);
        LocalDate parse = LocalDate.parse("2017-09-20", dateTimeFormatter);
        System.out.println(parse); //2017-09-20
    }
 
开发者ID:daishicheng,项目名称:outcomes,代码行数:21,代码来源:Main.java

示例7: main

import java.time.format.FormatStyle; //导入依赖的package包/类
public static void main(String[] args) {
    TreeSet<String> languageCodes = new TreeSet<String>();
    for (Locale locale : Locale.getAvailableLocales()) {
        languageCodes.add(locale.getLanguage());

    }

    LocalTime localTime = LocalTime.of(17, 30, 20);

    for (String languageCode : languageCodes) {

        Locale localeForLanguage = new Locale(languageCode);
        // Locale localeForLanguage = Locale.forLanguageTag(languageCode);
        DateTimeFormatter format = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT).withLocale(localeForLanguage);
        System.out.print(localeForLanguage.getDisplayLanguage() + ": ");
        System.out.print(format.format(localTime) + "\n");
    }

}
 
开发者ID:LGoodDatePicker,项目名称:LGoodDatePicker,代码行数:20,代码来源:GetAllLanguages.java

示例8: generateDefaultFormatterBCE

import java.time.format.FormatStyle; //导入依赖的package包/类
/**
 * generateDefaultFormatterBCE, This returns a default formatter for the specified locale, that
 * can be used for displaying or parsing BC dates. The formatter is generated from the default
 * FormatStyle.LONG formatter in the specified locale. The resulting format is intended to be
 * nearly identical to the default formatter used for AD dates.
 */
public static DateTimeFormatter generateDefaultFormatterBCE(Locale pickerLocale) {
    // This is verified to work for the following locale languages:
    // en, de, fr, pt, ru, it, nl, es, pl, da, ro, sv, zh.
    String displayFormatterBCPattern = DateTimeFormatterBuilder.getLocalizedDateTimePattern(
            FormatStyle.LONG, null, IsoChronology.INSTANCE, pickerLocale);
    displayFormatterBCPattern = displayFormatterBCPattern.replace("y", "u");
    // Note: We could have used DateUtilities.createFormatterFromPatternString(), which should
    // have the same formatter options as this line. We kept this code independent in case
    // anyone ever mistakenly changes that utility function.
    DateTimeFormatter displayFormatterBC = new DateTimeFormatterBuilder().parseLenient()
            .parseCaseInsensitive().appendPattern(displayFormatterBCPattern)
            .toFormatter(pickerLocale);
    // Get the local language as a string.
    String language = pickerLocale.getLanguage();
    // Override the format for the turkish locale to remove the name of the weekday.
    if ("tr".equals(language)) {
        displayFormatterBC = PickerUtilities.createFormatterFromPatternString(
                "dd MMMM uuuu", pickerLocale);
    }
    return displayFormatterBC;
}
 
开发者ID:LGoodDatePicker,项目名称:LGoodDatePicker,代码行数:28,代码来源:InternalUtilities.java

示例9: parseDate

import java.time.format.FormatStyle; //导入依赖的package包/类
public static Date parseDate(String s) {
	FormatStyle[] styles = new FormatStyle[] { FormatStyle.SHORT, FormatStyle.MEDIUM, FormatStyle.LONG, FormatStyle.FULL };
	for (int i = 0; i < styles.length; i++) {
		try {
			DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDate(styles[i]);
			LocalDate lcd = LocalDate.parse(s, formatter);
			return Date.from(lcd.atStartOfDay(ZoneId.systemDefault()).toInstant());
		} catch (Exception ex) {

		}
	}
	SimpleDateFormat[] formats = new SimpleDateFormat[] { new SimpleDateFormat("HH:mm:ss") };
	for (int i = 0; i < formats.length; i++) {
		try {
			return formats[i].parse(s);
		} catch (Exception e) {
		}
	}
	throw new ClassCastException("cannot cast to date");
}
 
开发者ID:inshua,项目名称:vba-interpreter,代码行数:21,代码来源:VbValue.java

示例10: setupLocalDateTextField

import java.time.format.FormatStyle; //导入依赖的package包/类
public static void setupLocalDateTextField(TextField textField) {
    textField.textProperty().addListener((observable, oldValue, newValue) -> {
        DateTimeFormatter dtf = new DateTimeFormatterBuilder().appendLocalized(FormatStyle.SHORT, null).toFormatter(Locale.getDefault());
        if (newValue!=null){
            try {
                dtf.parse(newValue);
                textField.getStyleClass().removeIf(c->"error".equals(c));
            } catch (DateTimeParseException e) {
                textField.getStyleClass().add("error");
            }

        }
    });


}
 
开发者ID:factoryfx,项目名称:factoryfx,代码行数:17,代码来源:TypedTextFieldHelper.java

示例11: formatDateShouldWork

import java.time.format.FormatStyle; //导入依赖的package包/类
@Test
public void formatDateShouldWork() {
    final Temporals temporals = new Temporals(Locale.US);
    Assert.assertEquals("6/30/09", temporals.formatDate(ZonedDateTime.now().withYear(2009).withMonth(6).withDayOfMonth(30), FormatStyle.SHORT));
    Assert.assertEquals("6/30/09 7:03:47 AM", temporals.formatDateTime(
            ZonedDateTime.now()
            .withYear(2009).withMonth(6).withDayOfMonth(30)
            .withHour(7).withMinute(3).withSecond(47),
            FormatStyle.SHORT,
            FormatStyle.MEDIUM
    ));
    Assert.assertEquals("10/26/14 1:30:00 AM", temporals.formatDateTime(
            ZonedDateTime.of(2014, 10, 26, 1, 30, 0, 0, ZoneId.of("UTC")),
            FormatStyle.SHORT,
            FormatStyle.MEDIUM
    ));
    Assert.assertEquals("March 1979", temporals.format(YearMonth.of(1979, 3), "MMMM yyyy"));
    Assert.assertEquals("2014.10.26 01:30", temporals.format(ZonedDateTime.of(2014, 10, 26, 1, 30, 0, 0, ZoneId.of("UTC")), "yyyy.MM.dd HH:mm"));
}
 
开发者ID:EuregJUG-Maas-Rhine,项目名称:site,代码行数:20,代码来源:TemporalsTest.java

示例12: weekDayOfBirthday

import java.time.format.FormatStyle; //导入依赖的package包/类
public static String weekDayOfBirthday(String birthday, String year) {
    //напишите тут ваш код
    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("d.M.yyyy", Locale.ITALIAN);
    LocalDate localDate = LocalDate.parse(birthday, dateTimeFormatter);
    localDate = localDate.with(Year.parse(year));
    return DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL).withLocale(Locale.ITALIAN).format(localDate).split(" ")[0];

}
 
开发者ID:avedensky,项目名称:JavaRushTasks,代码行数:9,代码来源:Solution.java

示例13: formatDate

import java.time.format.FormatStyle; //导入依赖的package包/类
public String formatDate(String locale, LocalDate date) {
    String formatString = this.localize(locale, KEY_DATE_FORMAT);
    Locale javaLocale = getJavaLocale(locale);
    DateTimeFormatter formatter = formatString == KEY_DATE_FORMAT
            ? DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG).withLocale(javaLocale)
            : DateTimeFormatter.ofPattern(formatString, javaLocale);
    return formatter.format(date);
}
 
开发者ID:IANetworks,项目名称:Ducky-Mc-Duckerson,代码行数:9,代码来源:I18N.java

示例14: main

import java.time.format.FormatStyle; //导入依赖的package包/类
public static void main(String[] args) {
    DateTimeFormatter formatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG);
    LocalDate date = LocalDate.of(2057, 8, 11);
    LocalTime time01 = LocalTime.now();
    System.out.println(date.format(formatter));
    System.out.println(formatter.format(date));
    System.out.println(time01.format(formatter));

    // What happens if you pass a time object (LocalTime) instead of a date object
    // (LocalDate) in the preceding code? java.time.temporal.UnsupportedTemporalTypeException
    LocalTime time = LocalTime.now();
    System.out.println(formatter.format(time));

}
 
开发者ID:huby,项目名称:java-se8-oca-study-guide,代码行数:15,代码来源:Main.java

示例15: createSingleDayHeader

import java.time.format.FormatStyle; //导入依赖的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


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