Here you can find the source of convertDoubleTimeToDate(Number d)
Parameter | Description |
---|---|
d | a value in [0..1[ representing a day |
public static Date convertDoubleTimeToDate(Number d)
//package com.java2s; /******************************************************************************* * Copyright (c) 2010 BSI Business Systems Integration AG. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from ww w. j av a 2 s. c om*/ * BSI Business Systems Integration AG - initial API and implementation ******************************************************************************/ import java.util.Calendar; import java.util.Date; public class Main { public static final long DAY_MILLIS = 24L * 3600L * 1000L; /** * @param d * a value in [0..1[ representing a day * @return the time value as date in the range from 00:00 - 23:59:59 * @see #convertDateToDoubleTime(Date) inverse function */ public static Date convertDoubleTimeToDate(Number d) { if (d == null) { return null; } int m; if (d.doubleValue() < 0) { m = (int) (((long) (d.doubleValue() * DAY_MILLIS - 0.5)) % DAY_MILLIS); } else { m = (int) (((long) (d.doubleValue() * DAY_MILLIS + 0.5)) % DAY_MILLIS); } Calendar c = Calendar.getInstance(); c.clear(); c.set(Calendar.MILLISECOND, m % 1000); m = m / 1000; c.set(Calendar.SECOND, m % 60); m = m / 60; c.set(Calendar.MINUTE, m % 60); m = m / 60; c.set(Calendar.HOUR_OF_DAY, m % 24); if (m < 0) { c.add(Calendar.DAY_OF_MONTH, 1); } return c.getTime(); } }