Example usage for java.util Calendar SECOND

List of usage examples for java.util Calendar SECOND

Introduction

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

Prototype

int SECOND

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

Click Source Link

Document

Field number for get and set indicating the second within the minute.

Usage

From source file:Main.java

public static Date round2Hour(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);//from ww w  .j a  v a  2s  .  c  o  m
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}

From source file:Main.java

public static Calendar getEndOfDate(long time) {
    Calendar ret = Calendar.getInstance();
    ret.setTimeInMillis(time);/*from   w  ww .j a va 2s.c  o  m*/
    ret.set(Calendar.HOUR_OF_DAY, 23);
    ret.set(Calendar.MINUTE, 59);
    ret.set(Calendar.SECOND, 59);
    ret.set(Calendar.MILLISECOND, 999);

    return ret;
}

From source file:Main.java

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

    return ret;
}

From source file:Main.java

public static Calendar GetYesterdayLeftRange(Calendar today) {
    Calendar calendar = (Calendar) today.clone();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.add(Calendar.DAY_OF_MONTH, -1);
    calendar.add(Calendar.MINUTE, 0);
    return calendar;
}

From source file:Main.java

public static Calendar getCalendarAtMidnight(int relativeDayToToday) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.add(Calendar.DAY_OF_YEAR, relativeDayToToday);
    return calendar;
}

From source file:Main.java

public static long getTimeLongTenHours(int year, int month, int day) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(year, month, day);/*  w w w .j ava  2s.c  o m*/
    calendar.set(Calendar.HOUR_OF_DAY, 10);
    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 long timeInMillis(int hour, int minute) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, hour);
    calendar.set(Calendar.MINUTE, minute);
    calendar.set(Calendar.SECOND, 0);

    long timeBefore = calendar.getTimeInMillis();

    if (Calendar.getInstance().getTimeInMillis() > timeBefore)
        calendar.add(Calendar.DAY_OF_WEEK, 1);
    return calendar.getTimeInMillis();
}

From source file:Main.java

static Calendar toNearestWholeMinute(Calendar d) {
    Calendar c = new GregorianCalendar();
    c.setTime(d.getTime());/*from w  w  w . jav  a  2 s .c  o m*/

    if (c.get(Calendar.SECOND) >= 30)
        c.add(Calendar.MINUTE, 1);

    c.set(Calendar.SECOND, 0);

    return c;
}

From source file:Main.java

public static Calendar GetYesterdayRightRange(Calendar today) {
    Calendar calendar = (Calendar) today.clone();
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.add(Calendar.DAY_OF_MONTH, -1);
    calendar.add(Calendar.MINUTE, 0);
    return calendar;
}

From source file:Main.java

public static Calendar newInitializedCalendar() {
    Calendar newitem = Calendar.getInstance();
    newitem.set(Calendar.HOUR, 0);
    newitem.set(Calendar.MINUTE, newitem.getMinimum(Calendar.MINUTE));
    newitem.set(Calendar.SECOND, newitem.getMinimum(Calendar.SECOND));
    newitem.set(Calendar.MILLISECOND, newitem.getMinimum(Calendar.MILLISECOND));
    return newitem;
}