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 long getYearMonthDay(long date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(date);/*w ww  .j  av a  2s.co  m*/
    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 Long getYesterday() {
    Calendar yesterday = Calendar.getInstance();
    yesterday.setTimeZone(TimeZone.getDefault());

    yesterday.set(Calendar.SECOND, 0);
    yesterday.set(Calendar.MINUTE, 0);
    yesterday.set(Calendar.HOUR_OF_DAY, 1);
    yesterday.set(Calendar.MILLISECOND, 0);

    int day = yesterday.get(Calendar.DAY_OF_YEAR);

    yesterday.set(Calendar.DAY_OF_YEAR, day - 1);

    return yesterday.getTimeInMillis();
}

From source file:Main.java

public static Date toNearestWholeMinute(Date d) {
    Calendar c = new GregorianCalendar();
    c.setTime(d);//from  w w w  .  j av  a 2s .com

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

    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);

    return c.getTime();
}

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

public static Calendar tomorrow() {
    Calendar date = new GregorianCalendar();
    date.add(Calendar.DATE, 1);/* w ww  .ja  v  a  2 s.  c  o m*/
    date.set(Calendar.HOUR_OF_DAY, 0);
    date.set(Calendar.MINUTE, 0);
    date.set(Calendar.SECOND, 0);
    date.set(Calendar.MILLISECOND, 0);
    return date;
}

From source file:Main.java

public static long endOfThisMonth() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.DAY_OF_MONTH, 1);
    cal.set(Calendar.HOUR_OF_DAY, 23);
    cal.set(Calendar.MINUTE, 59);
    cal.set(Calendar.SECOND, 59);
    cal.set(Calendar.MILLISECOND, 999);
    cal.add(Calendar.MONTH, 1);/* ww w  .  ja va 2s .  c o m*/
    cal.add(Calendar.DATE, -1);
    Date date = cal.getTime();
    return date.getTime();
}

From source file:Main.java

public static Date trimSeconds(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);// w w  w .j a va2 s.  c  om
    calendar.set(Calendar.MILLISECOND, 0);
    calendar.set(Calendar.SECOND, 0);
    return calendar.getTime();
}

From source file:Main.java

public static Date getEndOfDate(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);/*from   ww w .  j a  va 2 s . c  o  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 Date getStartOfDate(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);/*from   w  ww. java 2s. co m*/
    calendar.set(Calendar.HOUR, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    return calendar.getTime();
}

From source file:Main.java

private static long getTimeInMillis() {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY, 21);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    return calendar.getTimeInMillis();
}