Java LocalDateTime Create getLocalDateTime(Date datetime, TimeZone timeZone)

Here you can find the source of getLocalDateTime(Date datetime, TimeZone timeZone)

Description

Find a java.time.LocalDateTime for the given user java.util.Date and java.util.TimeZone .

License

Open Source License

Parameter

Parameter Description
datetime java.util.Date source
timeZone java.util.TimeZone source

Return

corresponding to given datetime and timeZone

Declaration

public static LocalDateTime getLocalDateTime(Date datetime, TimeZone timeZone) 

Method Source Code

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

import java.util.Date;
import java.util.TimeZone;

import java.time.LocalDateTime;

import java.time.ZoneId;

public class Main {
    /**/*from  w w  w  .  j  a  va2 s .c  om*/
     * Find a {@link java.time.LocalDateTime} for the given user 
     * {@link java.util.Date} and {@link java.util.TimeZone}.
     * 
     * @param datetime {@link java.util.Date} source
     * @param timeZone {@link java.util.TimeZone} source
     * @return {@link java.time.LocalDateTime} corresponding to given datetime and timeZone
     */
    public static LocalDateTime getLocalDateTime(Date datetime, TimeZone timeZone) {
        if (datetime == null) {
            return null;
        }
        if (timeZone == null) {
            return null;
        }
        ZoneId zoneId = timeZone.toZoneId();
        return LocalDateTime.ofInstant(datetime.toInstant(), zoneId);
    }
}

Related

  1. asLocalDateTime(Date date)
  2. asLocalDateTime(Date date)
  3. getLocalDateTimeFromEpochMilli(long epochMillis)
  4. getLocalDateTimeFromMillis(final long millis)
  5. getLocalDateTimeFromMillis(long millis)
  6. localDateTime(Date date, Clock clock)