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
public static Date endOfThisMonth() { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE)); calendar.set(Calendar.HOUR, calendar.getActualMaximum(Calendar.HOUR)); calendar.set(Calendar.MINUTE, calendar.getActualMaximum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getActualMaximum(Calendar.SECOND)); calendar.set(Calendar.MILLISECOND, calendar.getActualMaximum(Calendar.MILLISECOND)); return calendar.getTime(); }
From source file:Main.java
public static Date beginOfThisMonth() { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE)); calendar.set(Calendar.HOUR, calendar.getActualMinimum(Calendar.HOUR)); calendar.set(Calendar.MINUTE, calendar.getActualMinimum(Calendar.MINUTE)); calendar.set(Calendar.SECOND, calendar.getActualMinimum(Calendar.SECOND)); calendar.set(Calendar.MILLISECOND, calendar.getActualMinimum(Calendar.MILLISECOND)); return calendar.getTime(); }
From source file:Main.java
public static Date lastTimeOfMonth(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date);//w w w.j a v a2 s . co m cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); cal.set(Calendar.HOUR_OF_DAY, cal.getActualMaximum(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, cal.getActualMaximum(Calendar.MINUTE)); cal.set(Calendar.SECOND, cal.getActualMaximum(Calendar.SECOND)); cal.set(Calendar.MILLISECOND, cal.getActualMaximum(Calendar.MILLISECOND)); return cal.getTime(); }
From source file:Main.java
public static Date firstTimeOfMonth(Date date) { Calendar cal = Calendar.getInstance(); cal.setTime(date);/* w w w . jav a2 s. c om*/ cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH)); cal.set(Calendar.HOUR_OF_DAY, cal.getActualMinimum(Calendar.HOUR_OF_DAY)); cal.set(Calendar.MINUTE, cal.getActualMinimum(Calendar.MINUTE)); cal.set(Calendar.SECOND, cal.getActualMinimum(Calendar.SECOND)); cal.set(Calendar.MILLISECOND, cal.getActualMinimum(Calendar.MILLISECOND)); return cal.getTime(); }
From source file:Main.java
/** * Returns Date object of the next day of d. * @return/*from ww w . j a va 2s . c o m*/ */ public static Date getNextDay(Date d) { Calendar c = Calendar.getInstance(); if (d != null) c.setTime(d); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); c.add(Calendar.DAY_OF_MONTH, 1); return c.getTime(); }
From source file:Main.java
public static long getEndOfDayMs(int year, int month, int day) { final Calendar date = Calendar.getInstance(); date.set(Calendar.YEAR, year); date.set(Calendar.MONTH, month); date.set(Calendar.DAY_OF_MONTH, day); date.set(Calendar.HOUR_OF_DAY, date.getActualMaximum(Calendar.HOUR_OF_DAY)); date.set(Calendar.MINUTE, date.getActualMaximum(Calendar.MINUTE)); date.set(Calendar.SECOND, date.getActualMaximum(Calendar.SECOND)); date.set(Calendar.MILLISECOND, date.getActualMaximum(Calendar.MILLISECOND)); return date.getTimeInMillis(); }
From source file:Main.java
public static long getStartOfDayMs(int year, int month, int day) { final Calendar date = Calendar.getInstance(); date.set(Calendar.YEAR, year); date.set(Calendar.MONTH, month); date.set(Calendar.DAY_OF_MONTH, day); date.set(Calendar.HOUR_OF_DAY, date.getActualMinimum(Calendar.HOUR_OF_DAY)); date.set(Calendar.MINUTE, date.getActualMinimum(Calendar.MINUTE)); date.set(Calendar.SECOND, date.getActualMinimum(Calendar.SECOND)); date.set(Calendar.MILLISECOND, date.getActualMinimum(Calendar.MILLISECOND)); return date.getTimeInMillis(); }
From source file:Main.java
public static boolean isInTimeNow(int start, int end) { Calendar calendar = new ThreadLocal<Calendar>() { protected Calendar initialValue() { return Calendar.getInstance(); }//from w w w .j a v a2 s . com }.get(); long current = System.currentTimeMillis(); calendar.setTimeInMillis(current); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); long originToday = calendar.getTimeInMillis(); long distance = current - originToday; if (start <= distance && distance <= end) { return true; } return false; }
From source file:MainClass.java
public static Timestamp makeTimestamp(int year, int month, int day, int hour, int minute, int second, int millisecond) { Calendar cal = new GregorianCalendar(); cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month - 1); cal.set(Calendar.DATE, day);/*from w w w . ja v a 2 s . c om*/ cal.set(Calendar.HOUR_OF_DAY, hour); cal.set(Calendar.MINUTE, minute); cal.set(Calendar.SECOND, second); cal.set(Calendar.MILLISECOND, millisecond); // now convert GregorianCalendar object to Timestamp object return new Timestamp(cal.getTimeInMillis()); }
From source file:Main.java
public static Time[] getTimesFromScheduleHour(char[] hoursArray) { Calendar begin = Calendar.getInstance(); Calendar end = Calendar.getInstance(); begin.set(Calendar.SECOND, 0); begin.set(Calendar.MILLISECOND, 0); end.set(Calendar.SECOND, 0);/*from w ww .ja va 2 s .c o m*/ end.set(Calendar.MILLISECOND, 0); char beginChar = hoursArray[0]; char endChar = hoursArray[hoursArray.length - 1]; switch (beginChar) { case 'A': begin.set(Calendar.HOUR_OF_DAY, 7); begin.set(Calendar.MINUTE, 30); break; case 'B': begin.set(Calendar.HOUR_OF_DAY, 8); begin.set(Calendar.MINUTE, 20); break; case 'C': begin.set(Calendar.HOUR_OF_DAY, 9); begin.set(Calendar.MINUTE, 10); break; case 'D': begin.set(Calendar.HOUR_OF_DAY, 10); begin.set(Calendar.MINUTE, 10); break; case 'E': begin.set(Calendar.HOUR_OF_DAY, 11); begin.set(Calendar.MINUTE, 10); break; case 'F': begin.set(Calendar.HOUR_OF_DAY, 12); begin.set(Calendar.MINUTE, 0); break; case 'G': begin.set(Calendar.HOUR_OF_DAY, 13); begin.set(Calendar.MINUTE, 0); break; case 'H': begin.set(Calendar.HOUR_OF_DAY, 13); begin.set(Calendar.MINUTE, 50); break; case 'I': begin.set(Calendar.HOUR_OF_DAY, 14); begin.set(Calendar.MINUTE, 50); break; case 'J': begin.set(Calendar.HOUR_OF_DAY, 15); begin.set(Calendar.MINUTE, 40); break; case 'L': begin.set(Calendar.HOUR_OF_DAY, 16); begin.set(Calendar.MINUTE, 40); break; case 'M': begin.set(Calendar.HOUR_OF_DAY, 17); begin.set(Calendar.MINUTE, 30); break; case 'N': begin.set(Calendar.HOUR_OF_DAY, 18); begin.set(Calendar.MINUTE, 30); break; case 'O': begin.set(Calendar.HOUR_OF_DAY, 19); begin.set(Calendar.MINUTE, 20); break; case 'P': begin.set(Calendar.HOUR_OF_DAY, 20); begin.set(Calendar.MINUTE, 20); break; case 'Q': begin.set(Calendar.HOUR_OF_DAY, 21); begin.set(Calendar.MINUTE, 10); break; default: return null; } switch (endChar) { case 'A': end.set(Calendar.HOUR_OF_DAY, 8); end.set(Calendar.MINUTE, 20); break; case 'B': end.set(Calendar.HOUR_OF_DAY, 9); end.set(Calendar.MINUTE, 10); break; case 'C': end.set(Calendar.HOUR_OF_DAY, 10); end.set(Calendar.MINUTE, 10); break; case 'D': end.set(Calendar.HOUR_OF_DAY, 11); end.set(Calendar.MINUTE, 0); break; case 'E': end.set(Calendar.HOUR_OF_DAY, 12); end.set(Calendar.MINUTE, 0); break; case 'F': end.set(Calendar.HOUR_OF_DAY, 12); end.set(Calendar.MINUTE, 50); break; case 'G': end.set(Calendar.HOUR_OF_DAY, 13); end.set(Calendar.MINUTE, 50); break; case 'H': end.set(Calendar.HOUR_OF_DAY, 14); end.set(Calendar.MINUTE, 40); break; case 'I': end.set(Calendar.HOUR_OF_DAY, 15); end.set(Calendar.MINUTE, 40); break; case 'J': end.set(Calendar.HOUR_OF_DAY, 16); end.set(Calendar.MINUTE, 30); break; case 'L': end.set(Calendar.HOUR_OF_DAY, 17); end.set(Calendar.MINUTE, 30); break; case 'M': end.set(Calendar.HOUR_OF_DAY, 18); end.set(Calendar.MINUTE, 20); break; case 'N': end.set(Calendar.HOUR_OF_DAY, 19); end.set(Calendar.MINUTE, 20); break; case 'O': end.set(Calendar.HOUR_OF_DAY, 20); end.set(Calendar.MINUTE, 10); break; case 'P': end.set(Calendar.HOUR_OF_DAY, 21); end.set(Calendar.MINUTE, 10); break; case 'Q': end.set(Calendar.HOUR_OF_DAY, 22); end.set(Calendar.MINUTE, 0); break; default: return null; } return new Time[] { new Time(begin.getTimeInMillis()), new Time(end.getTimeInMillis()) }; }