List of usage examples for java.time.format FormatStyle MEDIUM
FormatStyle MEDIUM
To view the source code for java.time.format FormatStyle MEDIUM.
Click Source Link
From source file:Main.java
public static void main(String[] args) { DateTimeFormatter dateFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM); System.out.println(dateFormatter.format(LocalDate.now())); // Current Local Date System.out.println(dateFormatter.parse("Jan 19, 2014").getClass().getName()); //java.time.format.Parsed System.out.println(dateFormatter.parse("Jan 19, 2014", LocalDate::from)); // Jan 19, 2014 }
From source file:Main.java
public static void main(String[] args) { DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.SHORT);/*from w ww . j a va 2 s. c om*/ System.out.println(dateTimeFormatter.format(LocalDateTime.now())); }
From source file:Main.java
public static void main(String... args) { DateTimeFormatter germanFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM) .withLocale(Locale.GERMAN); LocalDate xmas = LocalDate.parse("24.12.2014", germanFormatter); System.out.println(xmas);/*from w ww. ja va 2s .c o m*/ }
From source file:Main.java
public static void main(String[] args) { LocalDate ld = LocalDate.of(2014, Month.JUNE, 21); LocalTime lt = LocalTime.of(17, 30, 20); LocalDateTime ldt = LocalDateTime.of(ld, lt); DateTimeFormatter fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT); System.out.println("Formatter Default Locale: " + fmt.getLocale()); System.out.println("Short Date: " + fmt.format(ld)); fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM); System.out.println("Medium Date: " + fmt.format(ld)); fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.LONG); System.out.println("Long Date: " + fmt.format(ld)); fmt = DateTimeFormatter.ofLocalizedDate(FormatStyle.FULL); System.out.println("Full Date: " + fmt.format(ld)); fmt = DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT); System.out.println("Short Time: " + fmt.format(lt)); fmt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT); System.out.println("Short Datetime: " + fmt.format(ldt)); fmt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM); System.out.println("Medium Datetime: " + fmt.format(ldt)); // Use German locale to format the datetime in medius style fmt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(Locale.GERMAN); System.out.println(fmt.format(ldt)); // Use Indian(English) locale to format datetime in short style fmt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).withLocale(new Locale("en", "IN")); System.out.println(fmt.format(ldt)); // Use Indian(English) locale to format datetime in medium style fmt = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withLocale(new Locale("en", "IN")); System.out.println(fmt.format(ldt)); }
From source file:org.openlmis.fulfillment.web.util.StatusChangeDto.java
/** * Print createdDate for display purposes. * @return created date/*w w w . j a va2s. c o m*/ */ @JsonIgnore public String printDate() { Locale locale = LocaleContextHolder.getLocale(); String datePattern = DateTimeFormatterBuilder.getLocalizedDateTimePattern(FormatStyle.MEDIUM, FormatStyle.MEDIUM, Chronology.ofLocale(locale), locale); DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(datePattern); return dateTimeFormatter.format(createdDate); }
From source file:retsys.client.controller.DeliveryChallanReturnController.java
/** * Initializes the controller class.// w ww . ja v a2 s.c o m */ @Override public void initialize(URL url, ResourceBundle rb) { dc_date.setValue(LocalDate.now()); material_name.setCellValueFactory(new PropertyValueFactory<DCItem, String>("name")); brand_name.setCellValueFactory(new PropertyValueFactory<DCItem, String>("brand")); model_code.setCellValueFactory(new PropertyValueFactory<DCItem, String>("model")); units.setCellValueFactory(new PropertyValueFactory<DCItem, String>("model")); quantity.setCellValueFactory(new PropertyValueFactory<DCItem, Integer>("quantity")); amount.setCellValueFactory(new PropertyValueFactory<DCItem, Integer>("amount")); dcDetail.getColumns().setAll(material_name, brand_name, model_code, quantity, amount); // TODO AutoCompletionBinding<Item> bindForTxt_name = TextFields.bindAutoCompletion(txt_name, new Callback<AutoCompletionBinding.ISuggestionRequest, Collection<Item>>() { @Override public Collection<Item> call(AutoCompletionBinding.ISuggestionRequest param) { List<Item> list = null; try { LovHandler lovHandler = new LovHandler("items", "name"); String response = lovHandler.getSuggestions(param.getUserText()); list = (List<Item>) new JsonHelper().convertJsonStringToObject(response, new TypeReference<List<Item>>() { }); } catch (IOException ex) { Logger.getLogger(ProjectController.class.getName()).log(Level.SEVERE, null, ex); } return list; } }, new StringConverter<Item>() { @Override public String toString(Item object) { System.out.println("here..." + object); return object.getName() + " (ID:" + object.getId() + ")"; } @Override public Item fromString(String string) { throw new UnsupportedOperationException(); } }); //event handler for setting other item fields with values from selected Item object //fires after autocompletion bindForTxt_name.setOnAutoCompleted(new EventHandler<AutoCompletionBinding.AutoCompletionEvent<Item>>() { @Override public void handle(AutoCompletionBinding.AutoCompletionEvent<Item> event) { Item item = event.getCompletion(); //fill other item related fields txt_name.setUserData(item.getId()); txt_brand.setText(item.getBrand()); txt_model.setText(null); // item doesn't have this field. add?? txt_rate.setText(String.valueOf(item.getRate())); } }); AutoCompletionBinding<DeliveryChallan> bindForProject = TextFields.bindAutoCompletion(project, new Callback<AutoCompletionBinding.ISuggestionRequest, Collection<DeliveryChallan>>() { @Override public Collection<DeliveryChallan> call(AutoCompletionBinding.ISuggestionRequest param) { List<DeliveryChallan> list = null; try { LovHandler lovHandler = new LovHandler("deliverychallans", "name"); String response = lovHandler.getSuggestions(param.getUserText()); list = (List<DeliveryChallan>) new JsonHelper().convertJsonStringToObject(response, new TypeReference<List<DeliveryChallan>>() { }); } catch (IOException ex) { Logger.getLogger(ProjectController.class.getName()).log(Level.SEVERE, null, ex); } return list; } }, new StringConverter<DeliveryChallan>() { @Override public String toString(DeliveryChallan object) { System.out.println("here..." + object); String strDate = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM).format(LocalDateTime .ofInstant(object.getChallanDate().toInstant(), ZoneId.systemDefault())); return "Project:" + object.getProject().getName() + " DC Date:" + strDate + " DC No.:" + object.getId(); } @Override public DeliveryChallan fromString(String string) { throw new UnsupportedOperationException(); } }); bindForProject .setOnAutoCompleted(new EventHandler<AutoCompletionBinding.AutoCompletionEvent<DeliveryChallan>>() { @Override public void handle(AutoCompletionBinding.AutoCompletionEvent<DeliveryChallan> event) { DeliveryChallan dc = event.getCompletion(); dc_no.setText(dc.getId().toString()); dc_date.setValue(LocalDateTime .ofInstant(dc.getChallanDate().toInstant(), ZoneId.systemDefault()).toLocalDate()); dc_no.setText(dc.getId().toString()); project.setText(dc.getProject().getName() + " (ID:" + dc.getProject().getId() + ")"); deliverymode.setText(dc.getDeliveryMode()); concernperson.setText(dc.getConcernPerson()); ObservableList<DCItem> items = FXCollections.observableArrayList(); Iterator detailsIt = dc.getDeliveryChallanDetail().iterator(); while (detailsIt.hasNext()) { DeliveryChallanDetail detail = (DeliveryChallanDetail) detailsIt.next(); Item item = detail.getItem(); int id = item.getId(); String site = item.getSite(); String name = item.getName(); String brand = item.getBrand(); String model = null; int rate = item.getRate().intValue(); int quantity = detail.getQuantity(); int amount = detail.getAmount(); String units = detail.getUnits(); items.add(new DCItem(id, name + " (ID:" + id + ")", brand, model, rate, quantity, units, amount)); } dcDetail.setItems(items); populateAuditValues(dc); } }); txt_qty.focusedProperty().addListener(new ChangeListener<Boolean>() { @Override public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (!newValue) { calcAmount(); } } }); }
From source file:retsys.client.controller.PurchaseOrderConfirmController.java
/** * Initializes the controller class.// w w w. j a v a 2s. c om */ @Override public void initialize(URL url, ResourceBundle rb) { po_date.setValue(LocalDate.now()); loc_of_material.setCellValueFactory(new PropertyValueFactory<POItem, String>("location")); material_name.setCellValueFactory(new PropertyValueFactory<POItem, String>("name")); brand_name.setCellValueFactory(new PropertyValueFactory<POItem, String>("brand")); model_code.setCellValueFactory(new PropertyValueFactory<POItem, String>("model")); quantity.setCellValueFactory(new PropertyValueFactory<POItem, Integer>("quantity")); confirm.setCellValueFactory(new PropertyValueFactory<POItem, Boolean>("confirm")); confirm.setCellFactory(CheckBoxTableCell.forTableColumn(confirm)); billNo.setCellValueFactory(new PropertyValueFactory<POItem, String>("billNo")); billNo.setCellFactory(TextFieldTableCell.forTableColumn()); supervisor.setCellValueFactory(new PropertyValueFactory<POItem, String>("supervisor")); supervisor.setCellFactory(TextFieldTableCell.forTableColumn()); receivedDate.setCellValueFactory(new PropertyValueFactory<POItem, LocalDate>("receivedDate")); receivedDate.setCellFactory(new Callback<TableColumn<POItem, LocalDate>, TableCell<POItem, LocalDate>>() { @Override public TableCell<POItem, LocalDate> call(TableColumn<POItem, LocalDate> param) { TableCell<POItem, LocalDate> cell = new TableCell<POItem, LocalDate>() { @Override protected void updateItem(LocalDate item, boolean empty) { super.updateItem(item, empty); //To change body of generated methods, choose Tools | Templates. if (empty || item == null) { setText(null); setGraphic(null); } else { setText(formatter.format(item)); } } @Override public void startEdit() { super.startEdit(); System.out.println("start edit"); DatePicker dateControl = null; if (this.getItem() != null) { dateControl = new DatePicker(this.getItem()); } else { dateControl = new DatePicker(); } dateControl.valueProperty().addListener(new ChangeListener<LocalDate>() { @Override public void changed(ObservableValue<? extends LocalDate> observable, LocalDate oldValue, LocalDate newValue) { if (newValue == null) { cancelEdit(); } else { commitEdit(newValue); } } }); this.setGraphic(dateControl); } @Override public void cancelEdit() { super.cancelEdit(); System.out.println("cancel edit"); setGraphic(null); if (this.getItem() != null) { setText(formatter.format(this.getItem())); } else { setText(null); } } @Override public void commitEdit(LocalDate newValue) { super.commitEdit(newValue); System.out.println("commit edit"); setGraphic(null); setText(formatter.format(newValue)); } }; return cell; } }); poDetail.getColumns().setAll(loc_of_material, material_name, brand_name, model_code, quantity, confirm, receivedDate, billNo, supervisor); AutoCompletionBinding<PurchaseOrder> bindForTxt_name = TextFields.bindAutoCompletion(project, new Callback<AutoCompletionBinding.ISuggestionRequest, Collection<PurchaseOrder>>() { @Override public Collection<PurchaseOrder> call(AutoCompletionBinding.ISuggestionRequest param) { List<PurchaseOrder> list = null; try { LovHandler lovHandler = new LovHandler("purchaseorders", "name"); String response = lovHandler.getSuggestions(param.getUserText()); list = (List<PurchaseOrder>) new JsonHelper().convertJsonStringToObject(response, new TypeReference<List<PurchaseOrder>>() { }); } catch (IOException ex) { Logger.getLogger(ProjectController.class.getName()).log(Level.SEVERE, null, ex); } return list; } }, new StringConverter<PurchaseOrder>() { @Override public String toString(PurchaseOrder object) { System.out.println("here..." + object); String strDate = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM).format( LocalDateTime.ofInstant(object.getDate().toInstant(), ZoneId.systemDefault())); return "Project:" + object.getProject().getName() + " PO Date:" + strDate + " PO No.:" + object.getId(); } @Override public PurchaseOrder fromString(String string) { throw new UnsupportedOperationException(); } }); bindForTxt_name .setOnAutoCompleted(new EventHandler<AutoCompletionBinding.AutoCompletionEvent<PurchaseOrder>>() { @Override public void handle(AutoCompletionBinding.AutoCompletionEvent<PurchaseOrder> event) { populateData(event.getCompletion()); } }); AutoCompletionBinding<Vendor> bindForVendor = TextFields.bindAutoCompletion(vendor, new Callback<AutoCompletionBinding.ISuggestionRequest, Collection<Vendor>>() { @Override public Collection<Vendor> call(AutoCompletionBinding.ISuggestionRequest param) { List<Vendor> list = null; try { LovHandler lovHandler = new LovHandler("vendors", "name"); String response = lovHandler.getSuggestions(param.getUserText()); list = (List<Vendor>) new JsonHelper().convertJsonStringToObject(response, new TypeReference<List<Vendor>>() { }); } catch (IOException ex) { Logger.getLogger(ProjectController.class.getName()).log(Level.SEVERE, null, ex); } return list; } }, new StringConverter<Vendor>() { @Override public String toString(Vendor object) { return object.getName() + " (ID:" + object.getId() + ")"; } @Override public Vendor fromString(String string) { throw new UnsupportedOperationException(); } }); }
From source file:org.sakaiproject.assignment.impl.AssignmentServiceImpl.java
@Override public String getUsersLocalDateTimeString(Instant date) { if (date == null) return ""; ZoneId zone = userTimeService.getLocalTimeZone().toZoneId(); DateTimeFormatter df = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM, FormatStyle.SHORT) .withZone(zone).withLocale(resourceLoader.getLocale()); return df.format(date); }
From source file:org.talend.dataquality.statistics.datetime.utils.PatternListGenerator.java
private static List<LocaledPattern> processBaseDateTimePatternsByLocales() { // Set<String> dateTimePatternsList = new LinkedHashSet<String>(); List<LocaledPattern> dateTimePatterns = new ArrayList<LocaledPattern>(); for (FormatStyle style : FORMAT_STYLES) { if (PRINT_DETAILED_RESULTS) { System.out.println("--------------------Date Style: " + style + "-----------------------"); }//from ww w.j a v a 2 s.c o m for (Locale locale : localeArray) { getFormatByStyle(style, style, true, false, locale, true);// Date Only } } for (FormatStyle style : FORMAT_STYLES) { if (PRINT_DETAILED_RESULTS) { System.out.println("--------------------DateTime Style: " + style + "-----------------------"); } for (Locale locale : localeArray) { getFormatByStyle(style, style, true, true, locale, true); // Date & Time } } // include additional combinations for (Locale locale : primaryLocaleArray) { getFormatByStyle(FormatStyle.SHORT, FormatStyle.MEDIUM, true, true, locale, false); getFormatByStyle(FormatStyle.MEDIUM, FormatStyle.SHORT, true, true, locale, false); } dateTimePatterns.removeAll(knownPatternList); // return new ArrayList<String>(dateTimePatterns); return dateTimePatterns; }
From source file:org.talend.dataquality.statistics.datetime.utils.PatternListGenerator.java
private static void generateDateFormats() throws IOException { int currentLocaledPatternSize = 0; knownLocaledPatternList.clear();//from w w w.j av a 2 s . c o m knownPatternList.clear(); // 1. Base Localized DateTimePatterns (java8 DateTimeFormatterBuilder) processBaseDateTimePatternsByLocales(); int basePatternCount = knownLocaledPatternList.size() - currentLocaledPatternSize; if (PRINT_DETAILED_RESULTS) { System.out.println("#basePatterns = " + basePatternCount + "\n"); } currentLocaledPatternSize = knownLocaledPatternList.size(); // 2. Other common DateTime patterns for (LocaledPattern lp : OTHER_COMMON_PATTERNS_NEED_COMBINATION) { addLocaledPattern(lp); for (Locale locale : primaryLocaleArray) { String patternShort = DateTimeFormatterBuilder.getLocalizedDateTimePattern(// null, FormatStyle.SHORT, IsoChronology.INSTANCE, locale);// LocaledPattern combinedShortLP = new LocaledPattern(lp.pattern + " " + patternShort, locale, FormatStyle.SHORT.name(), true); addLocaledPattern(combinedShortLP); String patternMedium = DateTimeFormatterBuilder.getLocalizedDateTimePattern(// null, FormatStyle.MEDIUM, IsoChronology.INSTANCE, locale);// LocaledPattern combinedMediumLP = new LocaledPattern(lp.pattern + " " + patternMedium, locale, FormatStyle.MEDIUM.name(), true); addLocaledPattern(combinedMediumLP); } } for (LocaledPattern lp : OTHER_COMMON_PATTERNS) { addLocaledPattern(lp); } // 3. ISO and RFC DateTimePatterns processISOAndRFCDateTimePatternList(); // knownPatternList.addAll(isoPatternList); int isoPatternCount = knownLocaledPatternList.size() - currentLocaledPatternSize; if (PRINT_DETAILED_RESULTS) { System.out.println("#DateTimePattern(ISO&RFC) = " + isoPatternCount + "\n"); } currentLocaledPatternSize = knownLocaledPatternList.size(); // 4. Additional Localized DateTimePatterns (java8 DateTimeFormatterBuilder) processAdditionalDateTimePatternsByLocales(); // knownPatternList.addAll(additionalPatternList); int additionalPatternCount = knownLocaledPatternList.size() - currentLocaledPatternSize; if (PRINT_DETAILED_RESULTS) { System.out.println("#additionalPatternList = " + additionalPatternCount + "\n"); } currentLocaledPatternSize = knownLocaledPatternList.size(); if (PRINT_DETAILED_RESULTS) { System.out.println("#Total = " + knownLocaledPatternList.size() + // " (#baseDatePatterns = " + basePatternCount + // ", #isoPatterns = " + isoPatternCount + // ", #additionalPatterns = " + additionalPatternCount + ")\n");// } // table header dateSampleFileTextBuilder.append("Sample\tPattern\tLocale\tFormatStyle\tIsWithTime\n"); RegexGenerator regexGenerator = new RegexGenerator(); for (LocaledPattern lp : knownLocaledPatternList) { datePatternFileTextBuilder.append(lp).append("\n"); String regex = regexGenerator.convertPatternToRegex(lp.pattern); dateRegexFileTextBuilder.append(lp.getPattern()).append("\t^").append(regex).append("$\n"); dateSampleFileTextBuilder .append(ZONED_DATE_TIME.format(DateTimeFormatter.ofPattern(lp.getPattern(), lp.getLocale()))) .append("\t").append(lp.getPattern())// .append("\t").append(lp.getLocale())// .append("\t").append(lp.getFormatStyle())// .append("\t").append(lp.isWithTime()).append("\n"); } // Date Formats String path = SystemDateTimePatternManager.class.getResource("DateFormats.txt").getFile().replace( "target" + File.separator + "classes", "src" + File.separator + "main" + File.separator + "resources"); IOUtils.write(datePatternFileTextBuilder.toString(), new FileOutputStream(new File(path))); // Date Regexes path = SystemDateTimePatternManager.class.getResource("DateRegexes.txt").getFile().replace( "target" + File.separator + "classes", "src" + File.separator + "main" + File.separator + "resources"); IOUtils.write(dateRegexFileTextBuilder.toString(), new FileOutputStream(new File(path))); // Date Samples path = SystemDateTimePatternManager.class.getResource("DateSampleTable.txt").getFile().replace( "target" + File.separator + "classes", "src" + File.separator + "test" + File.separator + "resources"); IOUtils.write(dateSampleFileTextBuilder.toString(), new FileOutputStream(new File(path))); // generate grouped Date Regexes FormatGroupGenerator.generateDateRegexGroups(); }