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:Main.java
/** Convert a calendar date into a string as specified by http://tools.ietf.org/html/rfc822#section-5.1 * @param date the calendar instance to convert to a string * @param locale the locale to use when outputting strings such as a day of the week, or month of the year. * @return a string in the format: "day_abbreviation, day_of_month month_abbreviation year hour:minute:second GMT" *///from w w w. ja v a 2 s. c o m // package-private - unused static final String convertDateToStringRfc822(Calendar date, Locale locale) { Date a = Date.from(Instant.now()); a.toString(); int day = date.get(Calendar.DAY_OF_MONTH); int hour = date.get(Calendar.HOUR_OF_DAY); int minute = date.get(Calendar.MINUTE); int second = date.get(Calendar.SECOND); String str = date.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, locale) + ", " + (day < 10 ? "0" + day : day) + " " + date.getDisplayName(Calendar.MONTH, Calendar.SHORT, locale) + " " + date.get(Calendar.YEAR) + " " + (hour < 10 ? "0" + hour : hour) + ":" + (minute < 10 ? "0" + minute : minute) + ":" + (second < 10 ? "0" + second : second) + " GMT"; return str; }
From source file:Main.java
/** * Packs java time value into an MS-DOS time value. * @param time the time value//from w w w.j ava 2s . c om * @return the MS-DOS packed time */ public static int packTime(long time) { Calendar c = Calendar.getInstance(); c.setTime(new Date(time)); int seconds = c.get(Calendar.SECOND); int minutes = c.get(Calendar.MINUTE); int hours = c.get(Calendar.HOUR_OF_DAY); /* * Here is how MS-DOS packs a time value: * 0-4: seconds (divided by 2 because we only have 5 bits = 32 different numbers) * 5-10: minutes (6 bits = 64 possible values) * 11-15: hours (5 bits = 32 possible values) * * source: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724247(v=vs.85).aspx */ return (hours << 11) & (minutes << 5) & (seconds / 2); }
From source file:Main.java
public static void zeroFromHour(Calendar calendar) { calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.MILLISECOND, 0); }
From source file:Main.java
/** * Calculate the Julian Day for a given date using the following formula: * JD = 367 * Y - INT(7 * (Y + INT((M + 9)/12))/4) + INT(275 * M / 9) * + D + 1721013.5 + UT/24/*w w w . j a va 2 s .c o m*/ * * Note that this is only valid for the year range 1900 - 2099. */ public static double calculateJulianDay(Date date) { Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); cal.setTime(date); double hour = cal.get(Calendar.HOUR_OF_DAY) + cal.get(Calendar.MINUTE) / 60.0f + cal.get(Calendar.SECOND) / 3600.0f; int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day = cal.get(Calendar.DAY_OF_MONTH); double jd = 367.0 * year - Math.floor(7.0 * (year + Math.floor((month + 9.0) / 12.0)) / 4.0) + Math.floor(275.0 * month / 9.0) + day + 1721013.5 + hour / 24.0; return jd; }
From source file:Main.java
private static void setEndOfDayToCalendar(Calendar c) { c.set(Calendar.HOUR_OF_DAY, 23); c.set(Calendar.MINUTE, 59); c.set(Calendar.SECOND, 59); }
From source file:Main.java
public static Date firstTimeOfMonth(Date date) { Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(date.getTime()); calendar.set(Calendar.HOUR_OF_DAY, 0); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.set(Calendar.DAY_OF_MONTH, 1); Date dateBegin = new Date(); dateBegin.setTime(calendar.getTimeInMillis()); return dateBegin; }
From source file:Main.java
public static String getTime() { Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(System.currentTimeMillis()); return cal.get(Calendar.HOUR_OF_DAY) + ":" + cal.get(Calendar.MINUTE) + ":" + cal.get(Calendar.SECOND); }
From source file:Main.java
public static Date startOfDay(Date origDate) { Calendar cal = Calendar.getInstance(); cal.setTime(origDate);/*w w w . j a v a2 s . c o m*/ cal.set(Calendar.HOUR_OF_DAY, 0); 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 getMidnight(Date date) { Calendar day = Calendar.getInstance(); day.setTime(date);// w ww. jav a2 s. c o m day.set(Calendar.HOUR_OF_DAY, 0); day.set(Calendar.MINUTE, 0); day.set(Calendar.SECOND, 0); day.set(Calendar.MILLISECOND, 0); day.add(Calendar.DAY_OF_MONTH, 0); return day.getTime(); }
From source file:Main.java
/** Helper method - creates a Phoenix date <I>String</I> from a Date object. @param dteValue <I>Date</I> object to be converted. @return A <I>String</I> that follows the format "YYYY-MM-DDTHH:NN:SS.00000". *//* w w w. j a v a 2 s . c om*/ public static String getXMLStringFromDate(Date dteValue) { if (null == dteValue) return null; Calendar pCalendar = Calendar.getInstance(); pCalendar.setTime(dteValue); // Return the String value. // Special treatment for the month because the current implementation // values January as 0. Code below should work if that ever changes. return pCalendar.get(Calendar.YEAR) + "-" + padNumber(pCalendar.get(Calendar.MONTH) + 1 - Calendar.JANUARY) + "-" + padNumber(pCalendar.get(Calendar.DAY_OF_MONTH)) + "T" + padNumber(pCalendar.get(Calendar.HOUR_OF_DAY)) + ":" + padNumber(pCalendar.get(Calendar.MINUTE)) + ":" + padNumber(pCalendar.get(Calendar.SECOND)); }