Java LocalDate to toCalendar(LocalDate localDate)

Here you can find the source of toCalendar(LocalDate localDate)

Description

to Calendar

License

Open Source License

Declaration

public static Calendar toCalendar(LocalDate localDate) 

Method Source Code

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

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;

import java.time.ZonedDateTime;

import java.util.Calendar;
import java.util.Date;

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

    public static Calendar toCalendar(LocalDate localDate) {
        if (localDate == null) {
            return null;
        }/*from w  ww  .  j a va2 s.c o  m*/
        Date date = toDate(localDate);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        ;
        return cal;
    }

    public static Calendar toCalendar(LocalDateTime dateTime) {
        if (dateTime == null) {
            return null;
        }
        Date date = toDate(dateTime);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        ;
        return cal;
    }

    public static Date toDate(LocalDateTime dateTime) {
        if (dateTime == null) {
            return null;
        }
        ZonedDateTime zonedDateTime = dateTime.atZone(DEFAULT_ZONEID);
        return Date.from(zonedDateTime.toInstant());
    }

    public static Date toDate(LocalDate localDate) {
        if (localDate == null) {
            return null;
        }
        ZonedDateTime zonedDateTime = localDate.atStartOfDay(DEFAULT_ZONEID);
        return Date.from(zonedDateTime.toInstant());
    }

    public static Date toDate(ZonedDateTime dateTime) {
        if (dateTime == null) {
            return null;
        }
        return Date.from(dateTime.toInstant());
    }
}

Related

  1. from(LocalDate localDate, LocalTime localTime)
  2. from(LocalDate localDate, LocalTime localTime, ZoneOffset zoneOffset)
  3. fromLocalDate(LocalDate date)
  4. fromLocalDate(LocalDate date, TimeZone timeZone)
  5. toBadDate(LocalDate localDate, ZoneId timezone)
  6. toDBString(LocalDate date)