Here you can find the source of parseCalendar(int year, int month, double day, TimeZone zone)
Parameter | Description |
---|---|
year | year value |
month | month of the year (first month is 1) |
day | day of the month including fraction of hours, minutes, seconds and milliseconds |
zone | the given time zone |
public static GregorianCalendar parseCalendar(int year, int month, double day, TimeZone zone)
//package com.java2s; /*/* w ww . j a va 2 s . c om*/ * Copyright (C) 2011-2012 Inaki Ortiz de Landaluce Saiz * * This program is free software: you can redistribute it * and/or modify it under the terms of the GNU General Public License * as published by the Free Software Foundation, either * version 3 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this program. If not, see * <http://www.gnu.org/licenses/> */ import java.util.Calendar; import java.util.GregorianCalendar; import java.util.TimeZone; public class Main { /** * Parses a date assuming all arguments are based on a Gregorian or Julian * calendar. * * @param year * year value * @param month * month of the year (first month is 1) * @param day * day of the month including fraction of hours, minutes, seconds * and milliseconds * @param zone * the given time zone * @return a calendar */ public static GregorianCalendar parseCalendar(int year, int month, double day, TimeZone zone) { // calculate hour, minutes, seconds and milliseconds double hour = (day % 1) * 24; // decimal part of a day times 24 double minute = (hour % 1) * 60; // decimal part of an hour times 60 double second = (minute % 1) * 60; // decimal part of a minute times 60 double millisecond = (second % 1) * 1000; return parseCalendar(year, month, (int) day, (int) hour, (int) minute, (int) second, (int) Math.round(millisecond), zone); } /** * Parses a date assuming all arguments are based on a Gregorian calendar. * * @param year * year value * @param month * month of the year (first month is 1) * @param day * day of the month (first day is 1) * @param hour * hour of the day for the 24-hour clock * @param minute * minute value within the hour * @param second * second value within the minute * @param millisecond * milliseconds value within the second * @param zone * the given time zone * @return a Gregorian calendar */ public static GregorianCalendar parseCalendar(int year, int month, int day, int hour, int minute, int second, int millisecond, TimeZone zone) { GregorianCalendar calendar = new GregorianCalendar(zone); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, month - 1); calendar.set(Calendar.DAY_OF_MONTH, (int) day); calendar.set(Calendar.HOUR_OF_DAY, (int) hour); calendar.set(Calendar.MINUTE, (int) minute); calendar.set(Calendar.SECOND, (int) second); calendar.set(Calendar.MILLISECOND, (int) Math.round(millisecond)); return calendar; } }