Java DateTimeFormatter formatDateAndTime(String dateAndTime)

Here you can find the source of formatDateAndTime(String dateAndTime)

Description

Parses a String to a LocalDateTime object like for example to '2015-12-15 12:30';

License

LGPL

Parameter

Parameter Description
dateAndTime The String that should be formatted and parsed to a LocalDateTime object.

Return

The formatted LocalDateTime Object of the passed String.

Declaration

public static LocalDateTime formatDateAndTime(String dateAndTime) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Main {
    /**//from ww w .ja va 2s . c om
     * Parses a String to a LocalDateTime object like for example to '2015-12-15 12:30';
     * 
     * @param dateAndTime
     *          The String that should be formatted and parsed to a LocalDateTime object.
     * @return The formatted LocalDateTime Object of the passed String.
     */
    public static LocalDateTime formatDateAndTime(String dateAndTime) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
        LocalDateTime formatedDate = LocalDateTime.parse(dateAndTime, formatter);
        return formatedDate;
    }
}

Related

  1. formatByLocale(Date date, Locale locale)
  2. formatDate(long date)
  3. formatDate(long milli)
  4. formatDate(long timestamp)
  5. formatDate(long timestamp)
  6. formatDateTime(Date dateTime)
  7. formatDateTime(long milis)
  8. formatISOUTCDateTime(long timestamp)
  9. formatNow(String format)