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 boolean isDateBeforeToday(Calendar calendar) {
    Calendar validationCalendar = Calendar.getInstance();
    validationCalendar.setTime(calendar.getTime());
    validationCalendar.set(Calendar.MILLISECOND, todayCalendar.get(Calendar.MILLISECOND));
    validationCalendar.set(Calendar.SECOND, todayCalendar.get(Calendar.SECOND));
    validationCalendar.set(Calendar.MINUTE, todayCalendar.get(Calendar.MINUTE));
    validationCalendar.set(Calendar.HOUR_OF_DAY, todayCalendar.get(Calendar.HOUR_OF_DAY));
    return validationCalendar.getTime().before(todayCalendar.getTime());
}

From source file:Main.java

public static Date truncateDate(Date date) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/* www  .j  a  v a2s. co  m*/
    cal.set(Calendar.HOUR, 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 void zeroFromHour(Calendar calendar) {
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
}

From source file:Main.java

public static Date startOfDay(Date origDate) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(origDate);/*from w ww . j a v  a 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 Date getMidnight(Date date) {
    Calendar day = Calendar.getInstance();
    day.setTime(date);/*  w w  w .  ja  va2  s. co  m*/
    day.set(Calendar.HOUR_OF_DAY, 0);
    day.set(Calendar.MINUTE, 0);
    day.set(Calendar.SECOND, 0);
    day.set(Calendar.MILLISECOND, 0);
    day.add(Calendar.DAY_OF_MONTH, 0);

    return day.getTime();
}

From source file:Main.java

public static Date getDateTimeFrom(int year, int monthOfYear, int dayOfMonth) {
    Calendar calendar = Calendar.getInstance();

    calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
    calendar.set(Calendar.MONTH, monthOfYear - 1);
    calendar.set(Calendar.YEAR, year);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    Date ret = calendar.getTime();
    return ret;//ww w . j ava 2 s.c  om
}

From source file:Main.java

public static Calendar getZeroSecondCalendar() {
    Calendar calendar = getCalendar();
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    return calendar;
}

From source file:Main.java

/**
 * Reset the time of a date//from  w w  w.jav a2 s . c om
 * @param date the date with time to reset
 * @return the 0 time date.
 */
public static Date zeroTimeDate(Date date) {
    final GregorianCalendar gregorianCalendar = new GregorianCalendar();
    gregorianCalendar.setTime(date);
    gregorianCalendar.set(Calendar.HOUR_OF_DAY, 0);
    gregorianCalendar.set(Calendar.MINUTE, 0);
    gregorianCalendar.set(Calendar.SECOND, 0);
    gregorianCalendar.set(Calendar.MILLISECOND, 0);
    return gregorianCalendar.getTime();
}

From source file:Main.java

/**
 * Decode a 16-bit encoded DOS date/time into a java date/time.
 * /*from   w w  w  .  j  a  v  a 2  s .c o m*/
 * @param dosDate
 * @param dosTime
 * @return long
 */
public static long decodeDateTime(int dosDate, int dosTime) {
    final Calendar cal = Calendar.getInstance();

    cal.set(Calendar.MILLISECOND, 0);
    cal.set(Calendar.SECOND, (dosTime & 0x1f) * 2);
    cal.set(Calendar.MINUTE, (dosTime >> 5) & 0x3f);
    cal.set(Calendar.HOUR_OF_DAY, dosTime >> 11);

    cal.set(Calendar.DATE, dosDate & 0x1f);
    cal.set(Calendar.MONTH, ((dosDate >> 5) & 0x0f) - 1);
    cal.set(Calendar.YEAR, 1980 + (dosDate >> 9));

    return cal.getTimeInMillis();
}

From source file:Dates.java

/**
 * If day, month and year are 0 return null.
 *///w ww .j  a v  a  2  s .  co  m
public static Date create(int day, int month, int year, int hourofday, int minute, int second) {
    if (day == 0 && month == 0 && year == 0)
        return null;
    Calendar cal = Calendar.getInstance();
    cal.set(year, month - 1, day, hourofday, minute, second);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();
}