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 int getMonth() {
    long ts = System.currentTimeMillis();
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(ts);
    return calendar.get(Calendar.MONTH) + 1;
}

From source file:Main.java

public static int getYesterdayMonth() {
    long ts = System.currentTimeMillis() - 24 * 3600000;
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(ts);
    return calendar.get(Calendar.MONTH) + 1;
}

From source file:Main.java

public static int getYesterdayDay() {
    long ts = System.currentTimeMillis() - 24 * 3600000;
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(ts);
    return calendar.get(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static int getDay() {
    long ts = System.currentTimeMillis();
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(ts);
    return calendar.get(Calendar.DAY_OF_MONTH);
}

From source file:Main.java

public static String millisToDate(long currentTime) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(currentTime);
    return calendar.get(Calendar.HOUR) + ":" + calendar.get(Calendar.MINUTE) + ":"
            + calendar.get(Calendar.SECOND) + " " + (calendar.get(Calendar.AM_PM) == 0 ? "AM" : "PM");
}

From source file:Main.java

public static int getYear() {
    long ts = System.currentTimeMillis();
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(ts);
    return calendar.get(Calendar.YEAR);
}

From source file:Main.java

public static String getTimeForm(long milliseconds) {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(milliseconds);
    StringBuffer sb = new StringBuffer();
    sb.append(c.get(c.YEAR)).append("-").append(c.get(c.MONTH) + 1).append("-").append(c.get(c.DAY_OF_MONTH))
            .append(" ").append(c.get(c.HOUR_OF_DAY)).append(":").append(c.get(c.MINUTE));
    return sb.toString();
}

From source file:Main.java

public static long getTimeInitializeMills(long mills) {
    Calendar c = Calendar.getInstance();
    c.setTimeInMillis(mills);
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);//from  w  ww .jav a 2 s. c  o m
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);

    return c.getTimeInMillis();
}

From source file:Main.java

public static Date formatEndDateForObject(String string) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(Long.valueOf(string));
    return calendar.getTime();
}

From source file:Main.java

public static void timeStamp(String tag) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    System.out.println("time stamp - " + calendar.get(Calendar.MINUTE) + ":" + calendar.get(Calendar.SECOND)
            + ":" + calendar.get(Calendar.MILLISECOND) + " -- " + tag);
}