Example usage for java.time.format DateTimeFormatter ofLocalizedDateTime

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

Introduction

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

Prototype

public static DateTimeFormatter ofLocalizedDateTime(FormatStyle dateStyle, FormatStyle timeStyle) 

Source Link

Document

Returns a locale specific date and time format for the ISO chronology.

Usage

From source file:Main.java

public static void main(String[] args) {
    DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM,
            FormatStyle.SHORT);//from w  w  w.  j ava2 s  .co m
    System.out.println(dateTimeFormatter.format(LocalDateTime.now()));

}

From source file:Main.java

public static void main(String[] args) {
    ZonedDateTime zonedDateTime = ZonedDateTime.of(2013, 1, 19, 0, 0, 0, 0, ZoneId.of("Europe/Paris"));

    DateTimeFormatter longDateTimeFormatter = DateTimeFormatter
            .ofLocalizedDateTime(FormatStyle.FULL, FormatStyle.FULL).withLocale(Locale.FRENCH);
    System.out.println(longDateTimeFormatter.getLocale()); // fr
    System.out.println(longDateTimeFormatter.format(zonedDateTime));

}

From source file:hash.HashFilesController.java

/**
 * Initializes the controller class.// w w  w.  ja va2s  .c om
 */
@Override
public void initialize(URL url, ResourceBundle rb) {
    SessionFactory sFactory = HibernateUtilities.getSessionFactory();
    Session session = sFactory.openSession();
    session.beginTransaction();

    Query query = session.createQuery("from Checksum where caseFile = " + CreateCaseController.getCaseNumber());
    List<Checksum> checksumsForCase = (List<Checksum>) query.list();

    checksumIDColumn.setCellValueFactory(new PropertyValueFactory("checksumID"));
    fileNameColumn.setCellValueFactory(new PropertyValueFactory("fileName"));
    filePathColumn.setCellValueFactory(new PropertyValueFactory("filePath"));
    dateTimeGeneratedColumn.setCellValueFactory(new PropertyValueFactory("dateTimeGenerated"));

    DateTimeFormatter format = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.SHORT);
    dateTimeGeneratedColumn.setCellFactory(column -> {
        return new TableCell<Checksum, LocalDateTime>() {
            @Override
            protected void updateItem(LocalDateTime item, boolean empty) {
                super.updateItem(item, empty);

                if (item == null || empty) {
                    setText(null);
                    setStyle("");
                } else {
                    // Format date.
                    setText(format.format(item));
                }
            }
        };
    });

    md5Column.setCellValueFactory(new PropertyValueFactory("MD5Value"));

    checksumTableView.getItems().addAll(checksumsForCase);
    session.getTransaction().commit();
    session.close();

}

From source file:hash.HashFilesController.java

private void generateChecksums(File file) {

    FileInputStream md5fis;/*from  w  w w . j a  v  a2s. c  om*/

    String md5 = "";

    try {
        md5fis = new FileInputStream(file);

        md5 = DigestUtils.md5Hex(md5fis);

        md5fis.close();

    } catch (IOException ex) {
        Logger.getLogger(HashFilesController.class.getName()).log(Level.SEVERE, null, ex);
    }

    Checksum aChecksum = new Checksum();
    aChecksum.setMD5Value(md5);
    ;
    aChecksum.setFileName(file.getName());
    aChecksum.setFilePath(file.getPath());

    DateTimeFormatter format = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.SHORT);
    LocalDateTime currentDateTime = LocalDateTime.now();
    currentDateTime.format(format);

    aChecksum.setDateTimeGenerated(currentDateTime);

    SessionFactory sFactory = HibernateUtilities.getSessionFactory();
    Session session = sFactory.openSession();
    session.beginTransaction();
    session.saveOrUpdate(aChecksum);

    CaseFile currentCase = (CaseFile) session.get(CaseFile.class, CreateCaseController.getCaseNumber());

    currentCase.getMd5Details().add(aChecksum);
    aChecksum.setCaseFile(currentCase);

    session.getTransaction().commit();
    session.close();

    checksumTableView.getItems().add(aChecksum);

    System.out.println(aChecksum.getMD5Value());
    System.out.println(aChecksum.getFileName());
    System.out.println(aChecksum.getFilePath());

}

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);
}