Here you can find the source of getTimeBoxValue(TimeZone zone, Date date)
Parameter | Description |
---|---|
zone | The TimeZone in which the Date will be rendered. |
date | The Date which should be displayed in the UTCTimeBox |
public static final Long getTimeBoxValue(TimeZone zone, Date date)
//package com.java2s; /*/*from w w w . ja v a 2 s . c o m*/ * Copyright 2010 Traction Software, Inc. * * 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.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.TimeZone; public class Main { /** * Returns an appropriate value for the UTCTimeBox for a specified * {@link TimeZone} and {@link Date}. * * @param zone * The {@link TimeZone} in which the Date will be * rendered. * * @param date * The Date which should be displayed in the UTCTimeBox * * @return the value for the UTCTimeBox or null if the supplied * date is null */ public static final Long getTimeBoxValue(TimeZone zone, Date date) { if (date == null) return null; // use a Calendar in the specified timezone to figure out the // time which is edited in a format independent of TimeZone. Calendar cal = GregorianCalendar.getInstance(zone); cal.setTime(date); // hh:mm (seconds and milliseconds are generally zero but we // include them as well) int hours = cal.get(Calendar.HOUR_OF_DAY); int minutes = cal.get(Calendar.MINUTE); int seconds = cal.get(Calendar.SECOND); int millis = cal.get(Calendar.MILLISECOND); return (((((hours * 60L) + minutes) * 60L) + seconds) * 1000L) + millis; } }