本文整理匯總了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;
}
示例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$
}
示例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},
};
}
示例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},
};
}
示例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"},
};
}
示例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
}
示例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");
}
}
示例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;
}
示例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");
}
示例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");
}
}
});
}
示例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"));
}
示例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];
}
示例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);
}
示例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));
}
示例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;
}