Android Long to Date Convert getNumberOfDaysPassed(long date1, long date2)

Here you can find the source of getNumberOfDaysPassed(long date1, long date2)

Description

Returns the number of days passed between two dates.

License

Apache License

Parameter

Parameter Description
date1 first date
date2 second date

Return

number of days passed between to dates.

Declaration

private synchronized static long getNumberOfDaysPassed(long date1,
        long date2) 

Method Source Code

/*/*from  www.  j  a v  a  2 s . c om*/
 * Copyright (C) 2006 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License 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 com.android.internal.R;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import java.util.Calendar;
import java.util.Date;
import java.util.Formatter;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;

public class Main{
    private static Time sThenTime;
    /**
     * Returns the number of days passed between two dates.
     *
     * @param date1 first date
     * @param date2 second date
     * @return number of days passed between to dates.
     */
    private synchronized static long getNumberOfDaysPassed(long date1,
            long date2) {
        if (sThenTime == null) {
            sThenTime = new Time();
        }
        sThenTime.set(date1);
        int day1 = Time.getJulianDay(date1, sThenTime.gmtoff);
        sThenTime.set(date2);
        int day2 = Time.getJulianDay(date2, sThenTime.gmtoff);
        return Math.abs(day2 - day1);
    }
}

Related

  1. getMinute(long dateTimeMillis)
  2. getMinutesSinceStartOfDay(long milliseconds)
  3. getMonth(long dateTimeMillis)
  4. getNameForDcim(long time)
  5. getNameForFile(long time)
  6. getReadableTimeStamp(long timeStamp)
  7. getReadableTimeUsage(long timeUsageMs)
  8. getRelativeDateLabel(long time)
  9. getRelativeTimeFromMilliSeconds(long dateInMillis)