Example usage for java.util Calendar HOUR

List of usage examples for java.util Calendar HOUR

Introduction

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

Prototype

int HOUR

To view the source code for java.util Calendar HOUR.

Click Source Link

Document

Field number for get and set indicating the hour of the morning or afternoon.

Usage

From source file:Main.java

public static Calendar clearTime(Calendar calendar) {
    calendar.clear(Calendar.HOUR_OF_DAY);
    calendar.clear(Calendar.HOUR);
    calendar.clear(Calendar.MINUTE);
    calendar.clear(Calendar.SECOND);
    calendar.clear(Calendar.MILLISECOND);

    return calendar;
}

From source file:Main.java

public static long getBeginOfCurrentDateInMillis() {
    Calendar calendar = Calendar.getInstance();
    calendar.clear(Calendar.HOUR);
    calendar.clear(Calendar.HOUR_OF_DAY);
    calendar.clear(Calendar.MINUTE);
    calendar.clear(Calendar.SECOND);
    calendar.clear(Calendar.MILLISECOND);
    return calendar.getTimeInMillis();
}

From source file:Main.java

private static Date get3HoursAgo() {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.HOUR, -3);

    return calendar.getTime();
}

From source file:Main.java

public static Calendar clearToDate(Calendar calendar) {
    return clear(calendar, Calendar.HOUR, Calendar.HOUR_OF_DAY, Calendar.MINUTE, Calendar.SECOND,
            Calendar.MILLISECOND);
}

From source file:Main.java

private static Date get8Hours10MinsAgo() {
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.HOUR, -8);
    calendar.add(Calendar.MINUTE, -10);

    return calendar.getTime();
}

From source file:Main.java

public static String getNextHourDateTime() {
    Calendar c = Calendar.getInstance();
    c.add(Calendar.HOUR, 1);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss");
    String nextTime = sdf.format(new Date(c.getTimeInMillis()));
    return nextTime;
}

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 Date getEndOfDate(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);/*from  www. j a  va  2 s .  co  m*/
    calendar.set(Calendar.HOUR, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    return calendar.getTime();
}

From source file:Main.java

public static long getDayInUTC(long time) {
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(time);//from   www.j a v  a 2s.c om
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    cal.setTimeZone(TimeZone.getTimeZone("UTC"));
    return cal.getTimeInMillis();
}

From source file:Main.java

public static Date getStartOfDate(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);/*from w w  w.j  av  a2  s.  c  o m*/
    calendar.set(Calendar.HOUR, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    return calendar.getTime();
}