Here you can find the source of fromLocalDate(LocalDate date, TimeZone timeZone)
Parameter | Description |
---|---|
date | Date to convert (may be null) |
timeZone | The time zone to use |
null
if given date was null
public static Date fromLocalDate(LocalDate date, TimeZone timeZone)
//package com.java2s; /*/*from ww w. j a v a 2 s . co m*/ * Copyright 2016-2017 Axioma srl. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ import java.time.LocalDate; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class Main { /** * Convert a {@link LocalDate} value into a {@link Date}, using default calendar and default time zone. * @param date Date to convert (may be null) * @return Converted {@link Date}, or <code>null</code> if given date was <code>null</code> */ public static Date fromLocalDate(LocalDate date) { return fromLocalDate(date, null); } /** * Convert a {@link LocalDate} value into a {@link Date}, using default calendar. * @param date Date to convert (may be null) * @param timeZone The time zone to use * @return Converted {@link Date}, or <code>null</code> if given date was <code>null</code> */ public static Date fromLocalDate(LocalDate date, TimeZone timeZone) { if (date != null) { final Calendar c = Calendar.getInstance(); if (timeZone != null) { c.setTimeZone(timeZone); } c.set(Calendar.YEAR, date.getYear()); c.set(Calendar.MONTH, date.getMonthValue() - 1); c.set(Calendar.DAY_OF_MONTH, date.getDayOfMonth()); c.set(Calendar.HOUR, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return c.getTime(); } return null; } }