Here you can find the source of createTime(int hour, int minute, int second)
java.sql.Time
constructor.
Parameter | Description |
---|---|
hour | 0 to 23 |
minute | 0 to 59 |
second | 0 to 59 |
Time
public static Time createTime(int hour, int minute, int second)
//package com.java2s; /*/*w w w.j a v a2 s. com*/ * JBoss, Home of Professional Open Source. * See the COPYRIGHT.txt file distributed with this work for information * regarding copyright ownership. Some portions may be licensed * to Red Hat, Inc. under one or more contributor license agreements. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301 USA. */ import java.sql.Time; import java.util.Calendar; import java.util.TimeZone; public class Main { private static ThreadLocal<Calendar> CAL = new ThreadLocal<Calendar>() { @Override protected Calendar initialValue() { return Calendar.getInstance(); } }; /** * Replaces deprecated <code>java.sql.Time</code> constructor. * * @param hour 0 to 23 * @param minute 0 to 59 * @param second 0 to 59 * @see java.sql.Time * @return A <code>Time</code> */ public static Time createTime(int hour, int minute, int second) { primeCalendar(); CAL.get().set(Calendar.HOUR_OF_DAY, hour); CAL.get().set(Calendar.MINUTE, minute); CAL.get().set(Calendar.SECOND, second); return new Time(CAL.get().getTimeInMillis()); } private static void primeCalendar() { CAL.get().setTimeZone(TimeZone.getDefault()); CAL.get().clear(); } }