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 int getStudyDay(Context context) {
    String startStr = getSP(context, SP_LOGIN).getString(SP_KEY_LOGIN_STUDY_STARTTIME, "");
    if (!startStr.equals("")) {
        long start = Long.parseLong(startStr);
        long current = Calendar.getInstance().getTimeInMillis();

        Calendar s = Calendar.getInstance();
        s.setTimeInMillis(start);//ww  w .j  ava2s  . c  o m
        s.set(Calendar.HOUR_OF_DAY, 3);
        s.set(Calendar.MINUTE, 0);
        s.set(Calendar.SECOND, 0);
        s.set(Calendar.MILLISECOND, 0);

        Calendar c = Calendar.getInstance();
        c.setTimeInMillis(current);
        //         c.set(Calendar.HOUR_OF_DAY, 12);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);

        start = s.getTimeInMillis();
        current = c.getTimeInMillis();

        return (int) ((current - start) / (24 * 60 * 60 * 1000));
    } else {
        return -1;
    }
}

From source file:Util.java

/**
 * Unpacks date stored in kdb format./*from w ww .  ja  va 2s. co m*/
 * 
 * @param d
 * @return
 */
public static Date unpackDate(byte[] d) {
    // Byte bits: 00000000 11111111 22222222 33333333 44444444
    // Contents : 00YYYYYY YYYYYYMM MMDDDDDH HHHHMMMM MMSSSSSS
    int year = (d[0] << 6) | ((d[1] >> 2) & 0x0000003F);
    int month = ((d[1] & 0x00000003) << 2) | ((d[2] >> 6) & 0x00000003);
    int day = (d[2] >> 1) & 0x0000001F;
    int hour = ((d[2] & 0x00000001) << 4) | ((d[3] >> 4) & 0x0000000F);
    int minute = ((d[3] & 0x0000000F) << 2) | ((d[4] >> 6) & 0x00000003);
    int second = d[4] & 0x0000003F;
    Calendar calendar = Calendar.getInstance();
    calendar.set(year, month - 1, day, hour, minute, second);
    calendar.set(Calendar.MILLISECOND, 0);
    return calendar.getTime();
}

From source file:Main.java

public static Date getTime(int year, int month, int day, int hour, int minute) {
    Calendar date = Calendar.getInstance();
    date.set(year, month, day, hour, minute, 0);
    date.set(Calendar.MILLISECOND, 0);
    return date.getTime();
}

From source file:Main.java

static void setDate(Calendar cal, int month, int date) {
    cal.clear();/* ww w  . j a v a  2 s  .c  o  m*/

    cal.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR));
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DATE, date);
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
}

From source file:Main.java

public static Date getFloorDate(Date d) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(d);//from  w  w w  .  ja v  a  2s  .co  m

    // Set time fields to zero
    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 getCeilDate(Date d) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date(d.getTime() + 1000 * 60 * 60));

    // Set time fields to zero
    cal.set(Calendar.MINUTE, 0);/*  w  ww .  j ava  2s  . c om*/
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    return cal.getTime();

}

From source file:Main.java

public static long getPeriodEnd(int periodType, long date) {
    final Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(getPeriodStart(periodType, date));

    switch (periodType) {
    case TYPE_DAY: {
        cal.add(Calendar.DAY_OF_YEAR, 1);
        break;//from   w  w  w .  j av  a2s  .  c o  m
    }

    case TYPE_WEEK: {
        cal.add(Calendar.WEEK_OF_YEAR, 1);
        break;
    }

    case TYPE_MONTH: {
        cal.add(Calendar.MONTH, 1);
        break;
    }

    case TYPE_YEAR: {
        cal.add(Calendar.YEAR, 1);
        break;
    }
    }

    cal.add(Calendar.MILLISECOND, -1);
    return cal.getTimeInMillis();
}

From source file:Main.java

public static void trimTimestamp(Calendar cal) {
    cal.set(Calendar.HOUR_OF_DAY, 0);
    cal.set(Calendar.MINUTE, 0);/*from   w w  w .  ja  v a 2s  .  c o m*/
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
}

From source file:Main.java

static void setDate(Calendar cal, int month, int date, boolean endOfDay) {
    cal.clear();/*  www .  j a va2  s.c o m*/
    cal.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR));
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DATE, date);
    if (endOfDay) {
        cal.set(Calendar.HOUR_OF_DAY, 23);
        cal.set(Calendar.MINUTE, 59);
        cal.set(Calendar.SECOND, 59);
        cal.set(Calendar.MILLISECOND, 999);
    } else {
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
    }
}

From source file:Main.java

public static boolean isDateAfterToday(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().after(todayCalendar.getTime());
}