Example usage for java.util Calendar MILLISECOND

List of usage examples for java.util Calendar MILLISECOND

Introduction

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

Prototype

int MILLISECOND

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

Click Source Link

Document

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

Usage

From source file:Main.java

public static Date rewindToBeginningOfDay(Date date) {
    Calendar cal = buildFromDate(date);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);/*from  w  w w  .ja va 2  s.co  m*/
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}

From source file:Main.java

public static Date round2Day(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/* w ww  .  java 2 s.  co  m*/
    cal.set(Calendar.HOUR_OF_DAY, 0);
    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 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;
}

From source file:Main.java

public static Calendar initCalendar(Date date) {

    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);//from   www .  j  av  a2  s.c o  m
    calendar.set(Calendar.HOUR, 10);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    return calendar;
}

From source file:Main.java

/**
 * Clean hours, minutes, seconds and milliseconds
 * @param c Calendar to clean//  w w w  .  j  a  v  a  2s  .  c om
 */
public static void cleanDay(Calendar c) {
    c.set(Calendar.HOUR_OF_DAY, 0);
    c.set(Calendar.MINUTE, 0);
    c.set(Calendar.SECOND, 0);
    c.set(Calendar.MILLISECOND, 0);
}

From source file:Main.java

public static long getStartOfWeek(long week) {
    Calendar calendar = getCalendarWithTime(week);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.clear(Calendar.MINUTE);
    calendar.clear(Calendar.SECOND);
    calendar.clear(Calendar.MILLISECOND);

    // get start of this week in milliseconds
    calendar.set(Calendar.DAY_OF_WEEK, calendar.getFirstDayOfWeek());

    return calendar.getTimeInMillis();
}

From source file:Main.java

public static long getTimeLongTenHours(int year, int month, int day) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(year, month, day);//from ww  w. j a  va2  s .c om
    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 Calendar GetThisMonthLeftRange(Calendar today) {
    Calendar calendar = (Calendar) today.clone();
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    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.MINUTE, 0);
    return calendar;
}

From source file:Main.java

public static Calendar GetLastMonthRightRange(Calendar today) {
    Calendar calendar = (Calendar) today.clone();
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    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.MINUTE, 0);
    return calendar;
}

From source file:Main.java

public static Calendar GetLastMonthLeftRange(Calendar today) {
    Calendar calendar = (Calendar) today.clone();
    calendar.set(Calendar.DAY_OF_MONTH, 1);
    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.MONTH, -1);
    calendar.add(Calendar.MINUTE, 0);
    return calendar;
}