Java TimeZone getDateBoxValue(TimeZone zone, Date date)

Here you can find the source of getDateBoxValue(TimeZone zone, Date date)

Description

Returns the value for the UTCDateBox for a specified TimeZone and Date .

License

Apache License

Parameter

Parameter Description
zone The TimeZone in which the Date will be rendered.
date The Date which should be displayed in the UTCTimeBox

Return

the value for the UTCDateBox or null if the supplied date is null

Declaration

public static final Long getDateBoxValue(TimeZone zone, Date date) 

Method Source Code

//package com.java2s;
/*/*w  w w  .j av  a 2 s  . c om*/
 * 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 the value for the UTCDateBox 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 UTCDateBox or null if the supplied date is null
     */
    public static final Long getDateBoxValue(TimeZone zone, Date date) {

        if (date == null)
            return null;

        // use a Calendar in the specified timezone to figure out the
        // date and then convert to GMT
        Calendar cal = GregorianCalendar.getInstance(zone);
        cal.setTime(date);

        Calendar gmt = GregorianCalendar.getInstance(TimeZone
                .getTimeZone("GMT"));

        // copy the year, month, and day
        gmt.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),
                cal.get(Calendar.DAY_OF_MONTH));

        // zero everything else out (for midnight)
        gmt.set(Calendar.HOUR_OF_DAY, 0);
        gmt.set(Calendar.MINUTE, 0);
        gmt.set(Calendar.SECOND, 0);
        gmt.set(Calendar.MILLISECOND, 0);

        // midnight at GMT on the date specified
        return gmt.getTimeInMillis();
    }
}

Related

  1. extractTimeZone(String strdate, Date thedate)
  2. getDateAtTimeZone(Date when, TimeZone from, TimeZone to)
  3. getDateAttributes(long millisec, TimeZone tz, boolean showNumber)
  4. getDateValue(TimeZone zone, Long dateBoxValue, Long timeBoxValue)
  5. getDateWithoutTimeZone(Date date)
  6. getExcelSerialDayNumber(Date date, Locale locale, TimeZone timeZone)
  7. getLocalTime( java.util.TimeZone localTimeZone, java.util.Date timestamp, java.util.TimeZone sourceTimeZone)