Example usage for java.util Calendar setTimeInMillis

List of usage examples for java.util Calendar setTimeInMillis

Introduction

In this page you can find the example usage for java.util Calendar setTimeInMillis.

Prototype

public void setTimeInMillis(long millis) 

Source Link

Document

Sets this Calendar's current time from the given long value.

Usage

From source file:Main.java

public static boolean isSameDate(long d1, long d2) {
    Calendar cal1 = Calendar.getInstance();
    cal1.setTimeInMillis(d1);
    Calendar cal2 = Calendar.getInstance();
    cal2.setTimeInMillis(d2);// www .  j ava2 s.  co m
    return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR)
            && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR);
}

From source file:Main.java

public static String getDate(long milliSeconds) {
    SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a");
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(milliSeconds);
    return formatter.format(calendar.getTime());
}

From source file:Main.java

public static Calendar getBeginOfDate(long time) {
    Calendar ret = Calendar.getInstance();
    ret.setTimeInMillis(time);
    ret.set(Calendar.HOUR_OF_DAY, 0);
    ret.set(Calendar.MINUTE, 0);/* w w  w.j a v a2s .  c o m*/
    ret.set(Calendar.SECOND, 0);
    ret.set(Calendar.MILLISECOND, 0);

    return ret;
}

From source file:Main.java

public static int[] getCurrentTime() {
    Calendar now = Calendar.getInstance();
    now.setTimeInMillis(System.currentTimeMillis());
    int[] time = new int[3];
    time[0] = now.get(Calendar.HOUR_OF_DAY);
    time[1] = now.get(Calendar.MINUTE);
    time[2] = now.get(Calendar.SECOND);
    return time;/*from  ww w.j  a  v  a2s  . c o  m*/
}

From source file:Main.java

public static String getDate(long milliSeconds) {

    SimpleDateFormat formatter = new SimpleDateFormat("EEEE dd MMMM yyyy", Locale.FRANCE);
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(milliSeconds);
    return formatter.format(calendar.getTime());
}

From source file:Main.java

public static String getFormattedDate(long pEpochMillis, String pFormat) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(pEpochMillis);
    return DateFormat.format(pFormat, calendar).toString();
}

From source file:Main.java

public static String getHour(long milliSeconds) {

    SimpleDateFormat formatter = new SimpleDateFormat("kk:mm", Locale.FRANCE);
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(milliSeconds);
    return formatter.format(calendar.getTime());
}

From source file:Main.java

public static int getInterval(long timeInMillis, long currentTimeInMillis) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(currentTimeInMillis);
    Long timeInMillisInterval = timeInMillis - calendar.getTimeInMillis();
    Float x = Float.valueOf(timeInMillisInterval) / 1000 / 3600 / 24;
    return (int) Math.ceil(x);
}

From source file:Main.java

public static long getStartOfTheDay(long date) {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(date);

    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);/*from w  w  w.j  av  a2  s  .  c o  m*/
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);

    return c.getTimeInMillis();
}

From source file:Main.java

private static Calendar calendarByMillis(long millis) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(millis);
    return calendar;
}