List of usage examples for java.util Calendar MILLISECOND
int MILLISECOND
To view the source code for java.util Calendar MILLISECOND.
Click Source Link
get
and set
indicating the millisecond within the second. From source file:Main.java
private static Calendar clearTimes(Calendar c) { c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0);/*from w w w .ja va 2 s.c om*/ c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return c; }
From source file:Main.java
public static java.util.Date getDateEnd(java.util.Date d) { Calendar c = Calendar.getInstance(); c.clear();//ww w . j a va 2 s . c o m Calendar co = Calendar.getInstance(); co.setTime(d); c.set(Calendar.DAY_OF_MONTH, co.get(Calendar.DAY_OF_MONTH)); c.set(Calendar.MONTH, co.get(Calendar.MONTH)); c.set(Calendar.YEAR, co.get(Calendar.YEAR)); c.add(Calendar.DAY_OF_MONTH, 1); c.add(Calendar.MILLISECOND, -1); return c.getTime(); }
From source file:Main.java
/** * Add the given amount of millis to the given calendar. The changes are reflected in the given * calendar./* ww w . j a v a2 s .c o m*/ * @param calendar The calendar to add the given amount of millis to. * @param millis The amount of millis to be added to the given calendar. Negative values are * also allowed, it will just go back in time. */ public static void addMillis(Calendar calendar, int millis) { calendar.add(Calendar.MILLISECOND, millis); }
From source file:Main.java
public static Date getDate(int year, int month, int day) { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month); cal.set(Calendar.DAY_OF_MONTH, day); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0);//from w w w .ja va 2 s .c o m cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); return cal.getTime(); }
From source file:Main.java
public static Date dayBegin(final Date date) { Calendar c = Calendar.getInstance(); c.setTime(date);/*from w w w . java 2 s . c o m*/ c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); return c.getTime(); }
From source file:Main.java
/** * Get the SunSet for the given date/*from w w w.j a v a 2 s . com*/ * @param date - input date * @return - Date with time specifying the Sun Set */ public static Date getSunSet(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(Calendar.HOUR_OF_DAY, 18); cal.set(Calendar.MINUTE, 00); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date ret = cal.getTime(); return ret; }
From source file:Main.java
/** * getDateEnd/* www. j ava 2s . c o m*/ * @param date the date that needs to be converted to an end date * @return a date at 11:59 PM */ public static Date getDateEnd(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(Calendar.HOUR_OF_DAY, 23); cal.set(Calendar.MINUTE, 59); cal.set(Calendar.SECOND, 59); cal.set(Calendar.MILLISECOND, 59); long time = cal.getTimeInMillis(); date.setTime(time); return date; }
From source file:Main.java
/** * Get the SunRise for the given date/*w w w . ja va 2 s . c o m*/ * @param date - input date * @return - Date with time specifying the Sun Rise */ public static Date getSunRise(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(Calendar.HOUR_OF_DAY, 06); cal.set(Calendar.MINUTE, 00); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); Date ret = cal.getTime(); return ret; }
From source file:Main.java
/** * Remove the time of a date value//www . jav a2s . co m * * @param date Date to remove the time part * @return A date with its time set to 00:00:00 */ public static Date removeTime(Date date) { GregorianCalendar gc = new GregorianCalendar(); gc.setTime(date); gc.set(Calendar.HOUR_OF_DAY, 0); gc.set(Calendar.MINUTE, 0); gc.set(Calendar.SECOND, 0); gc.set(Calendar.MILLISECOND, 0); return gc.getTime(); }
From source file:Main.java
public static Calendar getCalendarForTime(int repeatMode, int dayOfWeek, int hour, int minute, int second) { Calendar calendarNow = Calendar.getInstance(); Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.SECOND, second); calendar.set(Calendar.MILLISECOND, 0); if (repeatMode == 2) { int dayOfWeekAndroid = 0; // 7 stands for sunday for interface, but for android, sunday stands for 1. dayOfWeekAndroid = dayOfWeek % 7 + 1; calendar.set(Calendar.DAY_OF_WEEK, dayOfWeekAndroid); }//from w ww. j a va 2 s . c om // make sure the desire alarm time is in future. int tryCount = 0; int tryCountMax = 62; while (calendar.getTimeInMillis() < calendarNow.getTimeInMillis() && tryCount < tryCountMax) { if (repeatMode == 1) { calendar.add(Calendar.DAY_OF_YEAR, 1); } else if (repeatMode == 2) { calendar.add(Calendar.DAY_OF_YEAR, 7); } tryCount++; } Log.v("cpeng", "getCalendearForTime target info: " + calendar.toString()); return calendar; }