Example usage for java.util Date getTime

List of usage examples for java.util Date getTime

Introduction

In this page you can find the example usage for java.util Date getTime.

Prototype

public long getTime() 

Source Link

Document

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.

Usage

From source file:Main.java

public static CharSequence relativeDateString(Date date, Context context) {
    return android.text.format.DateUtils.getRelativeDateTimeString(context, date.getTime(),
            android.text.format.DateUtils.MINUTE_IN_MILLIS, android.text.format.DateUtils.WEEK_IN_MILLIS, 0);
}

From source file:Main.java

public static boolean between(Date date, Date date1, Date date2) {
    if (date.getTime() >= date1.getTime() && date.getTime() <= date2.getTime()) {
        return true;
    }//from w w  w . j  a v a 2  s .c o m
    return false;
}

From source file:Main.java

public static Date addMinutes(Date aDate, long minutes) {
    long millesecondsToAdd = 60 * 1000 * minutes;
    return new Date(aDate.getTime() + millesecondsToAdd);
}

From source file:Main.java

public static long interval(final Date date) {
    return (Calendar.getInstance(TimeZone.getTimeZone("GMT+08:00")).getTimeInMillis() - date.getTime()) / 1000;
}

From source file:Main.java

public static CharSequence friendlyTime(String dateStr) {
    Date date = formatDate(dateStr);
    return DateUtils.getRelativeTimeSpanString(date.getTime());
}

From source file:Main.java

public static Date getCeilDate(Date d) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date(d.getTime() + 1000 * 60 * 60));

    // Set time fields to zero
    cal.set(Calendar.MINUTE, 0);/*  w w  w.ja  va 2  s. co  m*/
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();

}

From source file:Main.java

public static Date addDays(Date p_date, double p_days) {
    long l_days = (long) (p_days * 1000 * 3600 * 24);

    return new Date(p_date.getTime() + l_days);
}

From source file:Main.java

public static long getTimeLong(String pattern, String dateString) {
    try {//from  ww w  .  j  a  v a  2s  .  c o m
        Date date = new SimpleDateFormat(pattern, Locale.getDefault()).parse(dateString);
        return date.getTime();
    } catch (ParseException e) {
        e.printStackTrace();
    }
    return -1;
}

From source file:Main.java

public static Date firstTimeOfWeek(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(date.getTime());

    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);

    Date dateBegin = new Date();
    dateBegin.setTime(calendar.getTimeInMillis());
    return dateBegin;
}

From source file:Main.java

public static int days(String day1, String day2, String format) {
    DateFormat df = new SimpleDateFormat(format);
    long days = 0;
    try {/*  w w w.j av  a2 s.  com*/
        Date d1 = df.parse(day1);
        Date d2 = df.parse(day2);
        long diff = Math.abs(d1.getTime() - d2.getTime());
        days = diff / (1000 * 60 * 60 * 24);
    } catch (Exception e) {
    }
    return (int) days;
}