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:Utils.java

public static Date getEndOfDay(Date day, Calendar cal) {
    if (day == null)
        day = new Date();
    cal.setTime(day);//from w w  w .ja v a  2 s .  c  o m
    cal.set(Calendar.HOUR_OF_DAY, cal.getMaximum(Calendar.HOUR_OF_DAY));
    cal.set(Calendar.MINUTE, cal.getMaximum(Calendar.MINUTE));
    cal.set(Calendar.SECOND, cal.getMaximum(Calendar.SECOND));
    cal.set(Calendar.MILLISECOND, cal.getMaximum(Calendar.MILLISECOND));
    return cal.getTime();
}

From source file:com.google.enterprise.connector.dctm.CheckpointTest.java

/** Gets the current date without milliseconds. */
private static Date now() {
    Calendar nowCalendar = Calendar.getInstance();
    nowCalendar.set(Calendar.MILLISECOND, 0);
    return nowCalendar.getTime();
}

From source file:com.joken.common.utils.ConverterUtils.java

/**
 * ?/*from  w  w w.  j a v a 2 s .  c o m*/
 * 
 * @param time
 *            :08:30:00
 * @param separator
 *            :
 * @return 
 */
public static Long string2TimeSeconds(String time, String separator) {
    Calendar cl = Calendar.getInstance();
    String[] times = time.split(separator);
    cl.set(Calendar.HOUR_OF_DAY, Integer.valueOf(times[0]));
    cl.set(Calendar.MINUTE, Integer.valueOf(times[1]));
    cl.set(Calendar.SECOND, Integer.valueOf(times[2]));
    cl.set(Calendar.MILLISECOND, 0);
    return cl.getTimeInMillis() / 1000;
}

From source file:de.codesourcery.eve.skills.util.Misc.java

public static Calendar stripToDay(Date d) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(d);//from   ww  w  .ja  v  a  2  s  .c  o  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;
}

From source file:Main.java

public static boolean isToday(long dateUtc) {
    final long currentTime = System.currentTimeMillis();
    final Calendar calendarBefore = Calendar.getInstance();
    calendarBefore.setTimeInMillis(currentTime);
    calendarBefore.set(Calendar.HOUR_OF_DAY, 0);
    calendarBefore.set(Calendar.MINUTE, 0);
    calendarBefore.set(Calendar.SECOND, 0);
    calendarBefore.set(Calendar.MILLISECOND, 0);

    ////from   w  w  w. j  av a2 s  .  c o m
    final Calendar calendarAfter = Calendar.getInstance();
    calendarAfter.setTimeInMillis(currentTime);
    calendarAfter.set(Calendar.HOUR_OF_DAY, 23);
    calendarAfter.set(Calendar.MINUTE, 59);
    calendarAfter.set(Calendar.SECOND, 59);
    calendarAfter.set(Calendar.MILLISECOND, 250);
    if ((dateUtc >= calendarBefore.getTimeInMillis()) && (dateUtc <= calendarAfter.getTimeInMillis())) {
        return true;
    }
    return false;
}

From source file:edu.zipcloud.core.util.DateUtil.java

public static Date getStartOfDay(Date date) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);/*from  ww  w  .  j  a  v  a 2s  . c o  m*/
    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();
}

From source file:Main.java

public static Calendar dateToCalendar(String strYear, String strMonth, String strDay, boolean b) {
    int year, month, day;
    try {//from  w  w w.j ava 2s.  c  o  m
        year = Integer.parseInt(strYear);
        month = Integer.parseInt(strMonth) - 1;
        day = Integer.parseInt(strDay);
    } catch (StringIndexOutOfBoundsException e) {
        return null;
    } catch (NumberFormatException e) {
        return null;
    }
    Calendar cal = Calendar.getInstance(TimeZone.getDefault());
    cal.setLenient(b);
    cal.set(year, month, day, 0, 0, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal;
}

From source file:DateHelper.java

/**
 * Calculating age from a current date/* w  w w  .  j av  a2 s. c om*/
 * 
 * @param current
 * @param birthdate
 * @return Age from the current (arg) date
 */
public static float getAge(final Date current, final Date birthdate) {

    if (birthdate == null) {
        return 0;
    }
    if (current == null) {
        return getAge(birthdate);
    } else {
        final Calendar calend = new GregorianCalendar();
        calend.set(Calendar.HOUR_OF_DAY, 0);
        calend.set(Calendar.MINUTE, 0);
        calend.set(Calendar.SECOND, 0);
        calend.set(Calendar.MILLISECOND, 0);

        calend.setTimeInMillis(current.getTime() - birthdate.getTime());

        float result = 0;
        result = calend.get(Calendar.YEAR) - 1970;
        result += (float) calend.get(Calendar.MONTH) / (float) 12;
        return result;
    }

}

From source file:com.liusoft.dlog4j.util.DateUtils.java

/**
 * ?//  w w w.  j  a v a2  s  . co m
 * @param date
 * @param time
 * @return
 */
public static Calendar mergeDateTime(Date date, Time time) {
    Calendar cal = Calendar.getInstance();
    if (date != null)
        cal.setTime(date);
    if (time != null) {
        Calendar temp = Calendar.getInstance();
        temp.setTime(time);
        cal.set(Calendar.HOUR_OF_DAY, temp.get(Calendar.HOUR_OF_DAY));
        cal.set(Calendar.MINUTE, temp.get(Calendar.MINUTE));
        cal.set(Calendar.SECOND, temp.get(Calendar.SECOND));
        cal.set(Calendar.MILLISECOND, temp.get(Calendar.MILLISECOND));
    }
    return cal;
}

From source file:com.ekom.ekomerp.global.DateTimeUtils.java

public static Calendar getCalendarWithoutTime(Date date, Locale locale) {
    Calendar calendar = Calendar.getInstance(locale);
    calendar.setTime(date);// ww w  .  j  a  v  a2 s .  c om
    calendar.set(Calendar.HOUR_OF_DAY, 0);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);
    return calendar;
}