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
/** * Converts time in dos format to Java format * @param dosTime/*from w ww . j a v a 2 s. c om*/ * @return time in java format */ public static long dosToJavaTme(int dosTime) { int sec = 2 * (dosTime & 0x1f); int min = (dosTime >> 5) & 0x3f; int hrs = (dosTime >> 11) & 0x1f; int day = (dosTime >> 16) & 0x1f; int mon = ((dosTime >> 21) & 0xf) - 1; int year = ((dosTime >> 25) & 0x7f) + 1980; Calendar cal = Calendar.getInstance(); cal.set(year, mon, day, hrs, min, sec); cal.set(Calendar.MILLISECOND, 0); return cal.getTime().getTime(); }
From source file:Main.java
public static Date setDateTime(Date originalDate, int hour, int minute, int second) { Calendar cal = new GregorianCalendar(); cal.setTime(originalDate);/* w w w. j a va 2 s . c o m*/ cal.set(Calendar.HOUR, hour); cal.set(Calendar.MINUTE, minute); cal.set(Calendar.SECOND, second); cal.set(Calendar.MILLISECOND, 0); return cal.getTime(); }
From source file:ezbake.services.provenance.graph.Utils.java
public static Date getCurrentDate() { // zero out millisecond Calendar cal = Calendar.getInstance(); cal.set(Calendar.MILLISECOND, 0); return cal.getTime(); }
From source file:edu.zipcloud.core.util.DateUtil.java
public static Date getEndOfDay(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTime(date);//from w w w . j a v a2 s . com calendar.set(Calendar.HOUR_OF_DAY, 23); calendar.set(Calendar.MINUTE, 59); calendar.set(Calendar.SECOND, 59); calendar.set(Calendar.MILLISECOND, 999); return calendar.getTime(); }
From source file:Main.java
/** * Creates a calendar object with the next absolute time determined by hour and minute * @param hourOfDay//from w w w.ja va2 s . c om * @param minute * @return */ public static Calendar getNextAlarmTimeAbsolute(int hourOfDay, int minute) { Calendar cal = Calendar.getInstance(); Calendar calNow = (Calendar) cal.clone(); cal.set(Calendar.HOUR_OF_DAY, hourOfDay); cal.set(Calendar.MINUTE, minute); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); if (cal.compareTo(calNow) <= 0) { //Today's time passed, count to tomorrow cal.add(Calendar.DATE, 1); } return cal; }
From source file:Main.java
/** * This method returns a new Date with a specified hour, minute, second and millis * * @param date//w w w .j a v a2s .c om * Start date * @param hourOfDay * Target hour (0 - 23) * @param minute * Target minute (0 - 59) * @param second * Target second (0 - 59) * @param millis * Target millis (0 - 999) * * @return The requested time */ public static Date setTime(Date date, int hourOfDay, int minute, int second, int millis) { Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(Calendar.HOUR_OF_DAY, hourOfDay); cal.set(Calendar.MINUTE, minute); cal.set(Calendar.SECOND, second); cal.set(Calendar.MILLISECOND, millis); return cal.getTime(); }
From source file:Utils.java
public static Date getEndOfMinute(Date day, Calendar cal) { if (day == null || cal == null) { return day; }/*from w w w . j a v a 2 s . com*/ cal.setTime(day); cal.set(Calendar.SECOND, cal.getMaximum(Calendar.SECOND)); cal.set(Calendar.MILLISECOND, cal.getMaximum(Calendar.MILLISECOND)); return cal.getTime(); }
From source file:Main.java
/** * Returns milliseconds of the date argument dt. If the argument * isIncludeTime is false then the returned milliseconds does not include * time./* w w w . j ava2 s .c o m*/ * * @param dt * @param isIncludeTime * @return */ private static long getDate(Date dt, boolean isIncludeTime) { Calendar cal = GregorianCalendar.getInstance(); cal.setTime(dt); if (!isIncludeTime) { cal.set(Calendar.HOUR, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); } return cal.getTimeInMillis(); }
From source file:Main.java
/** * @param startDateTime/*ww w . ja va 2 s . c o m*/ * @param endDateTime * @return the difference in days between the second timestamp and first */ public static double getDifferenceInDays(Timestamp startDateTime, Timestamp endDateTime) { int difference = 0; Calendar startCalendar = Calendar.getInstance(); startCalendar.setTime(startDateTime); Calendar endCalendar = Calendar.getInstance(); endCalendar.setTime(endDateTime); // First, get difference in whole days Calendar startCompare = Calendar.getInstance(); startCompare.setTime(startDateTime); startCompare.set(Calendar.HOUR_OF_DAY, 0); startCompare.set(Calendar.MINUTE, 0); startCompare.set(Calendar.SECOND, 0); startCompare.set(Calendar.MILLISECOND, 0); Calendar endCompare = Calendar.getInstance(); endCompare.setTime(endDateTime); endCompare.set(Calendar.HOUR_OF_DAY, 0); endCompare.set(Calendar.MINUTE, 0); endCompare.set(Calendar.SECOND, 0); endCompare.set(Calendar.MILLISECOND, 0); return (endCompare.getTimeInMillis() - startCompare.getTimeInMillis()) / (24 * 60 * 60 * 1000); }
From source file:Main.java
protected static String toString(GregorianCalendar g1) { StringBuilder buffer = new StringBuilder(); buffer.append(/* w w w. j av a 2s . co m*/ g1.get(Calendar.YEAR) + "/" + (g1.get(Calendar.MONTH) + 1) + "/" + g1.get(Calendar.DAY_OF_MONTH)); buffer.append(" "); buffer.append(g1.get(Calendar.HOUR_OF_DAY) + ":" + g1.get(Calendar.MINUTE) + ":" + g1.get(Calendar.SECOND) + "." + g1.get(Calendar.MILLISECOND)); return buffer.toString(); }