Here you can find the source of convertDateToDoubleTime(Date time)
Parameter | Description |
---|---|
time | a time (hh:mm:ss) in the interval 00:00:00 - 23:59:59 |
public static Double convertDateToDoubleTime(Date time)
//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:/*www . j a va 2 s . c o m*/ * 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 time * a time (hh:mm:ss) in the interval 00:00:00 - 23:59:59 * @return the time value as a double in the range from [0..1[ * @see #convertDoubleTimeToDate(Number) inverse function */ public static Double convertDateToDoubleTime(Date time) { if (time == null) { return null; } Calendar c = Calendar.getInstance(); c.setTime(time); double t = ((c.get(Calendar.HOUR_OF_DAY) * 60 + c.get(Calendar.MINUTE)) * 60 + c.get(Calendar.SECOND)) * 1000 + c.get(Calendar.MILLISECOND); Double d = new Double(t / DAY_MILLIS); // range check; if (d.doubleValue() < 0) { d = new Double(0); } if (d.doubleValue() > 1) { d = new Double(1); } return d; } }