Java LocalDateTime Format toLocalDateTime(String date, DateTimeFormatter formatter)

Here you can find the source of toLocalDateTime(String date, DateTimeFormatter formatter)

Description

to Local Date Time

License

Open Source License

Declaration

public static LocalDateTime toLocalDateTime(String date, DateTimeFormatter formatter) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static LocalDateTime toLocalDateTime(String date, DateTimeFormatter formatter) {
        try {/*  w w w  . ja  v  a2s .  c o m*/
            ZonedDateTime zonedDateTime = toZonedDateTime(date, formatter);
            return LocalDateTime.ofInstant(zonedDateTime.toInstant(), ZoneId.systemDefault());
        } catch (Exception e) {
            throw new IllegalArgumentException(e);
        }
    }

    public static ZonedDateTime toZonedDateTime(String date, DateTimeFormatter formatter) {
        try {
            return ZonedDateTime.parse(date, formatter);
        } catch (Exception e) {
            throw new IllegalArgumentException(e);
        }
    }
}

Related

  1. formattedWeek(LocalDateTime localDateTime)
  2. formatTime(LocalDateTime dateTime)
  3. formatTime(LocalDateTime time)
  4. localDateTime2Str(LocalDateTime localDateTime, String dateTimeFormatter)
  5. toDoubleExcelFormat(LocalDateTime date, boolean date1904)
  6. toString(LocalDateTime ldt, DateTimeFormatter formatter)