Java Date Convert convertDateToWindowsTime(Date javaDate)

Here you can find the source of convertDateToWindowsTime(Date javaDate)

Description

converts a java date to a windows time object (is this timezone safe?)

License

Open Source License

Parameter

Parameter Description
javaDate the java date to be converted to windows time

Return

the double representing the date in a form windows understands

Declaration

static public double convertDateToWindowsTime(Date javaDate) 

Method Source Code


//package com.java2s;
/*/*from  w ww  . ja  va  2 s  .  c  o  m*/
 * Copyright (c) 1999-2004 Sourceforge JACOB Project.
 * All rights reserved. Originator: Dan Adler (http://danadler.com).
 * Get more information about JACOB at http://sourceforge.net/projects/jacob-project
 *
 * 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 St, Fifth Floor, Boston, MA  02110-1301  USA
 */

import java.util.Calendar;
import java.util.Date;

public class Main {
    /**
     * converts a java date to a windows time object (is this timezone safe?)
     * 
     * @param javaDate
     *            the java date to be converted to windows time
     * @return the double representing the date in a form windows understands
     */
    static public double convertDateToWindowsTime(Date javaDate) {
        if (javaDate == null) {
            throw new IllegalArgumentException("cannot convert null to windows time");
        }
        return convertMillisecondsToWindowsTime(javaDate.getTime());
    }

    /**
     * Convert a Java time to a COM time.
     * 
     * @param milliseconds
     *            Java time.
     * @return COM time.
     */
    static public double convertMillisecondsToWindowsTime(long milliseconds) {
        double result = 0.0;

        // code from jacobgen:
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(milliseconds);
        milliseconds += (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)); // add GMT offset
        result = (milliseconds / 86400000D) + 25569D;

        return result;
    }
}

Related

  1. convertDateToInt(final Date date)
  2. convertDateToLong(int year, int month, int day, int hour, int minute, int second)
  3. convertDateToServerTimeZoneDateInMilliSec(String timeZoneName, long milliSecond)
  4. convertDateToTimeStamp(Date date)
  5. convertDateToUTC(Date date)
  6. convertDateValueToMillis(TimeZone tz, long dateValue)
  7. convertDoubleTimeToDate(Number d)
  8. convertFromFileman(String date)
  9. convertInputDateToString(Date inputDate)