Java LocalDateTime from convertToSystemTime(LocalDateTime userInput, ZoneId userZoneId)

Here you can find the source of convertToSystemTime(LocalDateTime userInput, ZoneId userZoneId)

Description

convert To System Time

License

Open Source License

Declaration

public static Instant convertToSystemTime(LocalDateTime userInput, ZoneId userZoneId) 

Method Source Code


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

import java.time.*;

import java.util.Objects;

public class Main {
    private static final ZoneId zoneSystem = ZoneId.systemDefault();

    public static Instant convertToSystemTime(LocalDateTime userInput, ZoneId userZoneId) {
        Objects.requireNonNull(userInput, "Local date time is required");
        Objects.requireNonNull(userZoneId);

        ZonedDateTime userTime = ZonedDateTime.of(userInput, userZoneId);
        ZonedDateTime systemTime = userTime.withZoneSameInstant(zoneSystem);

        return systemTime.toInstant();
    }/*from ww  w.  j  av a  2  s  .co m*/
}

Related

  1. convertToLocalDateTime(String time)
  2. dateToLocalDateTime(Date date)
  3. dateToLong(LocalDateTime date)
  4. localDateTimeFromDate(Date date)