Here you can find the source of getMillisDiff(long lhs, long rhs, int gregorianCalendarUnits)
public static float getMillisDiff(long lhs, long rhs, int gregorianCalendarUnits)
//package com.java2s; /****************************************************************************** * Copyright (c) 2004-2008 Whirlwind Match Limited. All rights reserved. * * This is open source software; you can use, redistribute and/or modify * it under the terms of the Open Software Licence v 3.0 as published by the * Open Source Initiative.// ww w . ja va 2 s . c om * * You should have received a copy of the Open Software Licence along with this * application. if not, contact the Open Source Initiative (www.opensource.org) *****************************************************************************/ import java.util.Calendar; public class Main { private static final double SECOND = 1000; private static final double MINUTE = SECOND * 60; private static final double HOUR = MINUTE * 60; private static final double DAY = HOUR * 24; private static final double WEEK = DAY * 7; private static final double YEAR = DAY * 365.25; public static float getMillisDiff(long lhs, long rhs, int gregorianCalendarUnits) { long millis = lhs - rhs; switch (gregorianCalendarUnits) { case Calendar.MILLISECOND: return millis; case Calendar.SECOND: return (float) (millis / SECOND); case Calendar.MINUTE: return (float) (millis / MINUTE); case Calendar.HOUR: return (float) (millis / HOUR); case Calendar.DAY_OF_WEEK: case Calendar.DAY_OF_MONTH: case Calendar.DAY_OF_YEAR: return (float) (millis / DAY); case Calendar.WEEK_OF_MONTH: case Calendar.WEEK_OF_YEAR: return (float) (millis / WEEK); case Calendar.YEAR: return (float) (millis / YEAR); default: return 0.0f; } } }