List of usage examples for java.util Calendar MINUTE
int MINUTE
To view the source code for java.util Calendar MINUTE.
Click Source Link
get
and set
indicating the minute within the hour. From source file:Main.java
public static void main(String[] args) { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:00Z"); Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 2015); cal.set(Calendar.MONTH, Calendar.SEPTEMBER); cal.set(Calendar.DATE, 1);/*from w w w. j a v a 2 s.c om*/ cal.set(Calendar.HOUR_OF_DAY, 12); cal.set(Calendar.MINUTE, 15); Date date = cal.getTime(); System.out.println(date); TimeZone tz = TimeZone.getTimeZone("IST"); dateFormat.setTimeZone(tz); String actual = dateFormat.format(date); System.out.println(actual); }
From source file:Main.java
public static void main(String[] args) { Calendar someTime = Calendar.getInstance(); someTime.set(Calendar.HOUR_OF_DAY, 17); someTime.set(Calendar.MINUTE, 0); someTime.set(Calendar.SECOND, 0); // convert it to java epoch date Date someDate = toEpochDate(someTime); // create a date object from java.sql.Time Date fromSqlTime = new Date(Time.valueOf("17:00:00").getTime()); // now do the comparison System.out.println("Some Date: " + someDate.toString()); System.out.println("Sql Time: " + fromSqlTime.toString()); System.out.println("Are they equal? " + someDate.equals(fromSqlTime)); }
From source file:Main.java
public static void main(String[] args) { GregorianCalendar gc = new GregorianCalendar(); // current year value int year = gc.get(Calendar.YEAR); System.out.println(year);//from w w w. j a va 2s.com // current month value int month = gc.get(Calendar.MONTH); System.out.println(month); // day of month int day = gc.get(Calendar.DAY_OF_MONTH); System.out.println(day); // hour value int hour = gc.get(Calendar.HOUR); System.out.println(hour); // minute value int minute = gc.get(Calendar.MINUTE); System.out.println(minute); // second values int second = gc.get(Calendar.SECOND); System.out.println(second); }
From source file:Main.java
public static void main(String[] args) throws Exception { SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd"); Date workDate = simpleDateFormat1.parse("2011-11-27"); Calendar workCalendar = Calendar.getInstance(); workCalendar.setTime(workDate);/* w ww. ja va 2 s . c o m*/ SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("HH:mm:ss"); Calendar time = Calendar.getInstance(); time.setTime(simpleDateFormat2.parse("06:00:00")); workCalendar.set(Calendar.HOUR_OF_DAY, time.get(Calendar.HOUR_OF_DAY)); workCalendar.set(Calendar.MINUTE, time.get(Calendar.MINUTE)); workCalendar.set(Calendar.SECOND, time.get(Calendar.SECOND)); Date newWorkDate = workCalendar.getTime(); SimpleDateFormat simpleDateFormat3 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); System.out.println(simpleDateFormat3.format(newWorkDate)); }
From source file:GregorianCalendarDemo.java
public static void main(String args[]) { String months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; int year;/*from w w w . j a va 2 s . c om*/ GregorianCalendar gcalendar = new GregorianCalendar(); System.out.print("Date: "); System.out.print(months[gcalendar.get(Calendar.MONTH)]); System.out.print(" " + gcalendar.get(Calendar.DATE) + " "); System.out.println(year = gcalendar.get(Calendar.YEAR)); System.out.print("Time: "); System.out.print(gcalendar.get(Calendar.HOUR) + ":"); System.out.print(gcalendar.get(Calendar.MINUTE) + ":"); System.out.println(gcalendar.get(Calendar.SECOND)); if (gcalendar.isLeapYear(year)) { System.out.println("The current year is a leap year"); } else { System.out.println("The current year is not a leap year"); } }
From source file:MainClass.java
public static void main(String args[]) { String months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; Calendar calendar = Calendar.getInstance(); System.out.print("Date: "); System.out.print(months[calendar.get(Calendar.MONTH)]); System.out.print(" " + calendar.get(Calendar.DATE) + " "); System.out.println(calendar.get(Calendar.YEAR)); System.out.print("Time: "); System.out.print(calendar.get(Calendar.HOUR) + ":"); System.out.print(calendar.get(Calendar.MINUTE) + ":"); System.out.println(calendar.get(Calendar.SECOND)); calendar.set(Calendar.HOUR, 10); calendar.set(Calendar.MINUTE, 29); calendar.set(Calendar.SECOND, 22); System.out.print("Updated time: "); System.out.print(calendar.get(Calendar.HOUR) + ":"); System.out.print(calendar.get(Calendar.MINUTE) + ":"); System.out.println(calendar.get(Calendar.SECOND)); }
From source file:Main.java
public static void main(String[] args) { String input = "2014-05-04 09:10:40.321"; // Prepare the pattern String pattern = "yyyy-MM-dd HH:mm:ss.SSS"; SimpleDateFormat sdf = new SimpleDateFormat(pattern); // Parse the text into a Date object Date dt = sdf.parse(input, new ParsePosition(0)); System.out.println(dt);/*from ww w. j a v a 2s. co m*/ // Get the Calendar instance Calendar cal = Calendar.getInstance(); cal.setTime(dt); // Print time parts System.out.println("Hour:" + cal.get(Calendar.HOUR)); System.out.println("Minute:" + cal.get(Calendar.MINUTE)); System.out.println("Second:" + cal.get(Calendar.SECOND)); System.out.println("Millisecond:" + cal.get(Calendar.MILLISECOND)); }
From source file:Main.java
public static void main(String[] args) throws Exception { Calendar start = Calendar.getInstance(); start.set(2015, 1, 21, 11, 1, 11);//from ww w. j a v a 2 s .co m Calendar end = Calendar.getInstance(); Calendar clone = (Calendar) start.clone(); int year = elapsed(clone, end, Calendar.YEAR); System.out.println(year + " year"); clone.add(Calendar.YEAR, year); int month = elapsed(clone, end, Calendar.MONTH); clone.add(Calendar.MONTH, month); System.out.println(month + " month"); int date = elapsed(clone, end, Calendar.DATE); clone.add(Calendar.DATE, date); System.out.println(date + " day"); int hour = (int) (end.getTimeInMillis() - clone.getTimeInMillis()) / 3600000; clone.add(Calendar.HOUR, hour); System.out.println(hour + " hour"); int minute = (int) (end.getTimeInMillis() - clone.getTimeInMillis()) / 60000; clone.add(Calendar.MINUTE, minute); System.out.println(minute + " minute"); int millis = (int) (end.getTimeInMillis() - clone.getTimeInMillis()) / 1000; System.out.println(millis + " millis"); }
From source file:com.cjwagner.InfoSecPriv.ExtensionServer.java
public static void main(String[] args) { initializeLogStore();//from w w w .jav a2 s. c o m get("/data", (request, response) -> { Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); cal.add(Calendar.MINUTE, -5); Date tMinusDelta = cal.getTime(); Map<String, LoggerMessage> filtered = new HashMap<String, LoggerMessage>(); for (Map.Entry<String, LoggerMessage> entry : logStore.entrySet()) { String ip = entry.getKey(); LoggerMessage logmess = entry.getValue(); LoggerMessage logmessFiltered = new LoggerMessage(); logmessFiltered.setFirstLogTime(logmess.getFirstLogTime()); List<LogData> filteredData = new ArrayList<LogData>(); logmessFiltered.setLogs(filteredData); for (LogData data : logmess.getLogs()) { if (data.getDate().after(tMinusDelta)) { filteredData.add(data); } } filtered.put(ip, logmessFiltered); } ObjectMapper objMapper = new ObjectMapper().configure(SerializationFeature.INDENT_OUTPUT, true); String jsonResponse = objMapper.writeValueAsString(filtered); System.out.println("Responded to query for recent data from IP: " + request.ip()); return jsonResponse; }); post("/LicenseRegistry", (request, response) -> { if (storeSize >= MAXSTORESIZE) { response.status(507);//insufficient storage return "Server storage full!"; } String ip = request.ip().replace(':', '_'); String json = request.body(); try { LoggerMessage logMess = LoggerMessage.fromJSON(json); logMess.setFirstLogTime(new Date()); LoggerMessage rec = logStore.get(ip); if (rec == null) { logStore.put(ip, logMess); rec = logMess; } else { rec.getLogs().addAll(logMess.getLogs()); } updateLogFile(ip, rec); storeSize += logMess.getLogs().size(); response.status(200); System.out.println("Recieved log data from IP: " + ip); return "LicenseKey:<c706cfe7-b748-4d75-98b5-c6b32ab789cb>"; } catch (JsonParseException jpe) { response.status(HTTP_BAD_REQUEST); System.out.println("Failed to parse log data from IP: " + ip); return jpe.getMessage(); } }); }
From source file:DayWeek.java
public static void main(String[] av) { //+//from w w w . j a v a 2 s.co m Calendar c = Calendar.getInstance(); // today System.out.println("Year: " + c.get(Calendar.YEAR)); System.out.println("Month: " + c.get(Calendar.MONTH)); System.out.println("Day: " + c.get(Calendar.DAY_OF_MONTH)); System.out.println("Day of week = " + c.get(Calendar.DAY_OF_WEEK)); System.out.println("Day of year = " + c.get(Calendar.DAY_OF_YEAR)); System.out.println("Week in Year: " + c.get(Calendar.WEEK_OF_YEAR)); System.out.println("Week in Month: " + c.get(Calendar.WEEK_OF_MONTH)); System.out.println("Day of Week in Month: " + c.get(Calendar.DAY_OF_WEEK_IN_MONTH)); System.out.println("Hour: " + c.get(Calendar.HOUR)); System.out.println("AM or PM: " + c.get(Calendar.AM_PM)); System.out.println("Hour (24-hour clock): " + c.get(Calendar.HOUR_OF_DAY)); System.out.println("Minute: " + c.get(Calendar.MINUTE)); System.out.println("Second: " + c.get(Calendar.SECOND)); //- }