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 firstTimeOfWeek(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(date.getTime());

    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);

    Date dateBegin = new Date();
    dateBegin.setTime(calendar.getTimeInMillis());
    return dateBegin;
}

From source file:Main.java

/**
 * Convert the day in calendar in the end of the day: 23:59:59.999
 * @param c Calendar to change// w  w  w.  j a  v  a2s .c o  m
 */
public static void endOfDay(Calendar c) {

    c.set(Calendar.HOUR_OF_DAY, 23);
    c.set(Calendar.MINUTE, 59);
    c.set(Calendar.SECOND, 59);
    c.set(Calendar.MILLISECOND, 999);
}

From source file:Main.java

public static float getPercentOfDay() {
    GregorianCalendar cal = new GregorianCalendar();
    float dayMillis = 0;
    dayMillis += (cal.get(Calendar.HOUR_OF_DAY) * 60 * 60);
    dayMillis += (cal.get(Calendar.MINUTE) * 60);
    dayMillis += cal.get(Calendar.SECOND);
    float totalDayMillis = (24f * 60f * 60f);
    return (dayMillis / totalDayMillis);
}

From source file:Main.java

public static Date getTheEndOfDate(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);/*from  www  .jav a 2s.  co  m*/
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);
    calendar.set(Calendar.MILLISECOND, 999);

    return calendar.getTime();
}

From source file:Main.java

/**
 * @return Return current day timestamp with YY, MM, dd info ONLY
 *///from w  ww .ja  va 2s .  co  m
public static Long getCurrentDayTS() {
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTimeInMillis();
}

From source file:Main.java

public static void setDateTime(long timeStamp, Calendar currentCalender, int i) {
    currentCalender.setTimeInMillis(timeStamp);
    currentCalender.set(Calendar.DATE, 1);
    currentCalender.set(Calendar.HOUR_OF_DAY, 0);
    currentCalender.set(Calendar.MINUTE, 0);
    currentCalender.set(Calendar.SECOND, 0);
    currentCalender.set(Calendar.MILLISECOND, 0);
    currentCalender.add(Calendar.DATE, i);
}

From source file:Main.java

public static Date getDateStart(Date date) {
    Calendar calendar = Calendar.getInstance();

    calendar.setTime(date);//from w w  w  .ja va 2s . co m
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);

    return calendar.getTime();
}

From source file:Main.java

public static Date getDateEnd(Date date) {
    Calendar calendar = Calendar.getInstance();

    calendar.setTime(date);//  ww  w  .ja v  a 2 s  .c  om
    calendar.set(Calendar.HOUR_OF_DAY, 23);
    calendar.set(Calendar.MINUTE, 59);
    calendar.set(Calendar.SECOND, 59);

    return calendar.getTime();
}

From source file:Main.java

public static long getTimeStampStartOfDay(long time) {
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    cal.setTime(new Date(time));
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);/*from   www.ja va2  s  .co m*/
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTimeInMillis();
}

From source file:Main.java

public static Date getTheBeginingOfDate(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);/*from   w  w w  . j av a  2s.com*/
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    return calendar.getTime();
}