summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap/bitmaskclient/base/utils/DateHelper.java
blob: 0476bf12feb3ff612b6214f0c1e5885245e5c685 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package se.leap.bitmaskclient.base.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * Contains helper methods related to date manipulation.
 *
 * @author Janak
 */
public class DateHelper {
    private static final String DATE_PATTERN = "dd/MM/yyyy";
    private static final int ONE_DAY = 86400000; //1000*60*60*24

    public static long getDateDiffToCurrentDateInDays(String startDate) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN, Locale.US);
        Date lastDate = sdf.parse(startDate);
        Date currentDate = new Date();
        return (currentDate.getTime() - lastDate.getTime()) / ONE_DAY;
    }

    public static String getCurrentDateString() {
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_PATTERN, Locale.US);
        Date lastDate = new Date();
        return sdf.format(lastDate);
    }
}