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


Java DateTimeFormatter.ofLocalizedDate方法代码示例

本文整理汇总了Java中java.time.format.DateTimeFormatter.ofLocalizedDate方法的典型用法代码示例。如果您正苦于以下问题:Java DateTimeFormatter.ofLocalizedDate方法的具体用法?Java DateTimeFormatter.ofLocalizedDate怎么用?Java DateTimeFormatter.ofLocalizedDate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.time.format.DateTimeFormatter的用法示例。


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

示例1: main

import java.time.format.DateTimeFormatter; //导入方法依赖的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: createDateTimeFormatter

import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
/**
 * Create a new {@code DateTimeFormatter} using this factory.
 * <p>If no specific pattern or style has been defined,
 * the supplied {@code fallbackFormatter} will be used.
 * @param fallbackFormatter the fall-back formatter to use when no specific
 * factory properties have been set (can be {@code null}).
 * @return a new date time formatter
 */
public DateTimeFormatter createDateTimeFormatter(DateTimeFormatter fallbackFormatter) {
	DateTimeFormatter dateTimeFormatter = null;
	if (StringUtils.hasLength(this.pattern)) {
		dateTimeFormatter = DateTimeFormatter.ofPattern(this.pattern);
	}
	else if (this.iso != null && this.iso != ISO.NONE) {
		switch (this.iso) {
			case DATE:
				dateTimeFormatter = DateTimeFormatter.ISO_DATE;
				break;
			case TIME:
				dateTimeFormatter = DateTimeFormatter.ISO_TIME;
				break;
			case DATE_TIME:
				dateTimeFormatter = DateTimeFormatter.ISO_DATE_TIME;
				break;
			case NONE:
				/* no-op */
				break;
			default:
				throw new IllegalStateException("Unsupported ISO format: " + this.iso);
		}
	}
	else if (this.dateStyle != null && this.timeStyle != null) {
		dateTimeFormatter = DateTimeFormatter.ofLocalizedDateTime(this.dateStyle, this.timeStyle);
	}
	else if (this.dateStyle != null) {
		dateTimeFormatter = DateTimeFormatter.ofLocalizedDate(this.dateStyle);
	}
	else if (this.timeStyle != null) {
		dateTimeFormatter = DateTimeFormatter.ofLocalizedTime(this.timeStyle);
	}

	if (dateTimeFormatter != null && this.timeZone != null) {
		dateTimeFormatter = dateTimeFormatter.withZone(this.timeZone.toZoneId());
	}
	return (dateTimeFormatter != null ? dateTimeFormatter : fallbackFormatter);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:47,代码来源:DateTimeFormatterFactory.java

示例3: updateList

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

示例4: main

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

示例5: getFallbackFormatter

import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
private DateTimeFormatter getFallbackFormatter(Type type) {
	switch (type) {
		case DATE: return DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT);
		case TIME: return DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT);
		default: return DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:8,代码来源:DateTimeFormatterRegistrar.java

示例6: main

import java.time.format.DateTimeFormatter; //导入方法依赖的package包/类
public static void main(String[] args) {
    DateTimeFormatter formatter
            = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG);
    LocalDate date = LocalDate.of(2057, 8, 11);
    System.out.println(formatter.format(date));
    System.out.println(date.format(formatter));
}
 
开发者ID:mkdika,项目名称:learnjava8,代码行数:8,代码来源:DateTimeFormatter1.java


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