List of usage examples for java.util Calendar SECOND
int SECOND
To view the source code for java.util Calendar SECOND.
Click Source Link
get
and set
indicating the second within the minute. From source file:com.wiiyaya.framework.common.utils.DateUtils.java
/** * 00:00:00/*from w w w . j a v a 2s . c om*/ * * @param date * @return ?? */ public static Date setDayStart(final Date date) { final Calendar c = Calendar.getInstance(); c.setLenient(false); c.setTime(date); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); return c.getTime(); }
From source file:Main.java
/** * This method returns a new Date with a specified hour, minute, second and millis * * @param date// www. j a v a 2 s . c o m * 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. java 2 s. c o m*/ 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
/** * Formats a date/time value as a string. * /*from w w w .jav a 2s . com*/ * @param date the date to format * @return the formatted date */ public static String formatDateTime(Calendar date) { StringBuilder builder = new StringBuilder(16); appendField(builder, date.get(Calendar.YEAR), 4); appendField(builder, date.get(Calendar.MONTH) + 1, 2); appendField(builder, date.get(Calendar.DAY_OF_MONTH), 2); appendField(builder, date.get(Calendar.HOUR_OF_DAY), 2); appendField(builder, date.get(Calendar.MINUTE), 2); appendField(builder, date.get(Calendar.SECOND), 2); return builder.toString(); }
From source file:com.intuit.tank.util.TimeFormatUtil.java
public static String formatTime(int numSeconds) { Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT")); c.setTimeInMillis(0);/*from www .java2 s . c om*/ c.add(Calendar.SECOND, numSeconds); return DF.format(c); }
From source file:Main.java
private static void setStartOfDayToCalendar(Calendar c) { c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); }
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.//from w w w . j av a 2 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/*from w w w .ja v a2 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(//from ww w. ja v a 2 s . c om 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(); }
From source file:Main.java
public static Calendar createCalendar(int hour, int minute) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.HOUR_OF_DAY, hour); calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.SECOND, 0); return calendar; }