Java Date Convert dateToQTime(final Date date)

Here you can find the source of dateToQTime(final Date date)

Description

Converts a Date object to a 32-bit value that be used in the file format.

License

Open Source License

Parameter

Parameter Description
date the date to convert

Return

the equivalent 32-bit value

Declaration

public static long dateToQTime(final Date date) 

Method Source Code

//package com.java2s;
/*//  w ww.  j a va  2s .com
 * libqcw - A library for parsing, manipulating, and writing QCharts (TM) 
 * workspace files.
 *
 * Copyright (C) 2008-2009 Jon Nall
 * QCharts is a registered service mark of eSignal, Inc.
 * RagingBull is a registered service mark of eSignal, Inc.
 *
 * Licensed under the Open Software License version 3.0 (the "License"); you
 * may not use this file except in compliance with the License. You should
 * have received a copy of the License along with this software; if not, you
 * may obtain a copy of the License at
 *
 * http://opensource.org/licenses/osl-3.0.php
 *
 * This software 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;

public class Main {
    private static long qEpochSeconds;

    /**
     * Converts a {@link Date} object to a 32-bit value that be used in the
     * file format.
     * 
     * Note that while a long is returned, the value will fit in 32 bits.
     * 
     * @param date the date to convert
     * @return the equivalent 32-bit value
     */
    public static long dateToQTime(final Date date) {
        final Calendar c = Calendar.getInstance();
        c.clear();
        c.setTime(date);
        if (c.getTimeZone().inDaylightTime(c.getTime())) {
            c.add(Calendar.HOUR_OF_DAY, 1);
        }

        final long seconds = c.getTimeInMillis() / 1000;

        long result;
        if (seconds >= 0) {
            // Post-1970. Add qEpoch
            result = seconds + qEpochSeconds;
        } else {
            // Pre-1970.
            result = qEpochSeconds - (-seconds);
        }
        result /= 2;

        return result;
    }
}

Related

  1. dateToJulian(Date date)
  2. dateToLong(final Date date)
  3. DateToMask(Date javaDateType)
  4. dateToMorining(Date date)
  5. dateToNumber(Date date)
  6. dateToRRNDate(Date date)
  7. DateToStr(java.util.Date val)
  8. dateToString(Date date)
  9. dateToString(Date date)