Example usage for java.time.format DateTimeFormatter ofLocalizedDate

List of usage examples for java.time.format DateTimeFormatter ofLocalizedDate

Introduction

In this page you can find the example usage for java.time.format DateTimeFormatter ofLocalizedDate.

Prototype

public static DateTimeFormatter ofLocalizedDate(FormatStyle dateStyle) 

Source Link

Document

Returns a locale specific date format for the ISO chronology.

Usage

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 germanFormatter = DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM)
            .withLocale(Locale.GERMAN);

    LocalDate xmas = LocalDate.parse("24.12.2014", germanFormatter);
    System.out.println(xmas);//from   w  ww .jav  a2s  .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:com.haulmont.chile.core.datatypes.impl.LocalDateDatatype.java

@Override
protected DateTimeFormatter getDateTimeFormatter() {
    return DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT);
}

From source file:com.bdb.weather.display.windrose.WindRosePane.java

/**
 * Load the wind rose data.// w  w  w .j a  v a  2s . co m
 * 
 * @param data The data
 */
public void loadData(WindRoseData data) {
    windRosePlot.clearCornerTextItems();

    if (data == null) {
        windRosePlot.setDataset((WindRoseData) null);
        return;
    }

    init(data.getSpeedBins());

    DateTimeFormatter sdf = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT);
    windRosePlot.setDataset(data);
    float calmPercent = ((float) data.getCalmDuration().getSeconds()
            / (float) data.getTotalDuration().getSeconds()) * 100.0f;
    windRosePlot.addCornerTextItem(String.format("Calm: %.1f%%", calmPercent));
    calmField.setText(String.format("%.1f", calmPercent));
    timeField.setText(sdf.format(data.getTime()));

    Speed maxSpeed = new Speed(0.0);
    Heading maxSpeedHeading = null;
    double speedSum = 0.0;

    //
    // Calculate annotation data
    //
    for (int i = 0; i < data.getNumSlices(); i++) {
        WindSlice slice = data.getSlice(i);

        Heading heading = Heading.headingForSlice(slice.getHeadingIndex(), data.getNumSlices());

        if (slice.getMaxSpeed().get() > maxSpeed.get()) {
            maxSpeed = slice.getMaxSpeed();
            maxSpeedHeading = heading;
        }

        speedSum += slice.getAvgSpeed().get() * slice.getSliceDuration().getSeconds();
    }

    //
    // Add annotations to the panel
    //
    if (maxSpeedHeading != null) {
        windRosePlot
                .addCornerTextItem(String.format("Max: %s@%s", maxSpeedHeading.getCompassLabel(), maxSpeed));
        Speed avgSpeed = new Speed(speedSum / data.getTotalDuration().getSeconds());
        windRosePlot.addCornerTextItem(String.format("Avg: %s", avgSpeed));
    }

    dataTable.setItems(FXCollections.observableList(data.getSlices()));
}

From source file:com.bdb.weather.display.freeplot.FreePlot.java

/**
 * Create a standard domain axis for the free plot panel
 * //from   w  w  w .j av a  2  s  . co  m
 * @param range The date range for this axis
 * @return The created axis
 */
private DateAxis createDomainAxis(DateRange range) {
    String startDate = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).format(range.getStart());
    String endDate = DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).format(range.getEnd());
    DateAxis axis = new DateAxis(startDate + " - " + endDate);
    return axis;
}

From source file:retsys.client.controller.DeliveryChallanReturnController.java

/**
 * Initializes the controller class./*from   ww  w.j a  v  a  2 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./*from   ww  w . j a  v  a 2s.  com*/
 */
@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();
                }
            });
}