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 String format(long timeInMillis, String format) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(timeInMillis);
    return format(calendar, format);
}

From source file:Main.java

public static String parseDateToString(long lastModify) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(lastModify);
    Date date = calendar.getTime();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss", Locale.CHINA);
    String time = sdf.format(date);
    return time;//from   ww  w  .  j  a va 2s  .  c  o m
}

From source file:Main.java

public static final String getStringTimeFromLong(final long timeInMillis) {

    final SimpleDateFormat format = new SimpleDateFormat("dd.MM.yy HH:mm");
    final Calendar c = Calendar.getInstance();
    c.setTimeInMillis(timeInMillis);
    c.setTimeZone(TimeZone.getDefault());
    return format.format(c.getTime());
}

From source file:Main.java

public static String getHour(long time) {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(time);
    int hour = c.get(Calendar.HOUR_OF_DAY);
    int minute = c.get(Calendar.MINUTE);
    String times = "" + hour;
    if (minute < 10) {
        times += ":0" + minute;
    } else {/*from   w w  w.  j  ava 2 s .  c  om*/
        times += ":" + minute;
    }
    return times;
}

From source file:Main.java

public static long getTimeMillisAsHourAndMinute(long millis) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(millis);
    int hour = calendar.get(Calendar.HOUR_OF_DAY);
    int minute = calendar.get(Calendar.MINUTE);
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minute);
    return calendar.getTimeInMillis();
}

From source file:Main.java

public static long getYearMonthDay(long date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(date);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    return calendar.getTimeInMillis();
}

From source file:Main.java

public static int isInSameDay(long day1, long day2) {
    Calendar c1 = Calendar.getInstance();
    c1.setTimeInMillis(day1);
    Calendar c2 = Calendar.getInstance();
    c2.setTimeInMillis(day2);/*from w w w  . ja v  a 2 s  .  com*/
    if (c1.get(Calendar.DAY_OF_YEAR) == c2.get(Calendar.DAY_OF_YEAR))
        return 0;
    else {
        return c1.get(Calendar.DAY_OF_YEAR) > c2.get(Calendar.DAY_OF_YEAR) ? 1 : -1;
    }

}

From source file:Main.java

public static int getMonthOfYear(long date) {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(date);
    return c.get(Calendar.MONTH);
}

From source file:Main.java

public static int getDayOfMonth(long date) {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(date);
    return c.get(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static long clearTime(long time) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(time);

    return clearTime(calendar).getTimeInMillis();
}