DateTime dt = new DateTime(1385577373517L, DateTimeZone.UTC); // Prints 2013-11-27T18:36:13.517Z System.out.println(dt); // Prints 2013-11-27T18:36:00.000Z (Floor rounded to a minute) System.out.println(dt.minuteOfDay().roundFloorCopy()); // Prints 2013-11-27T18:30:00.000Z (Rounded to custom minute Window) int windowMinutes = 10; System.out.println( dt.withMinuteOfHour((dt.getMinuteOfHour() / windowMinutes) * windowMinutes) .minuteOfDay().roundFloorCopy() );
private long getMilisFromDateClearDay(String createdAt) { DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'"); DateTime dt = formatter.parseDateTime(createdAt); return dt.minuteOfDay().roundFloorCopy().getMillis(); }
/** * Get current time rounded to minutes. * @return */ public static DateTime getNowAsDateTime() { final DateTime now = new DateTime(); final DateTime nowRounded = now.minuteOfDay().roundHalfCeilingCopy(); return nowRounded; }
private long getMilisFromDateClearDay(String createdAt) { DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'"); DateTime dt = formatter.parseDateTime(createdAt); return dt.minuteOfDay().roundFloorCopy().getMillis(); }
function boolean isBetween( DateTime dt, int start, int end ){ int hhmm = dt.hourOfDay()*100 + dt.minuteOfDay(); return start <= hhmm && hhmm < end; }
@Override public long process(DateTime timestamp) { return timestamp.minuteOfDay().roundFloorCopy().getMillis(); }
DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyyMMddHHmmss"); DateTime now = DateTime.now(); DateTime other1 = dtf.parseDateTime("20160418184137"); DateTime other2 = dtf.parseDateTime("20160418180000"); DateTime sharpHour = now.hourOfDay().roundFloorCopy(); if (!sharpHour.isEqual(other1.minuteOfDay().roundFloorCopy())) { System.out.println("Not matching sharp hour: " + other1); } DateTime other2Floor = other2.minuteOfDay().roundFloorCopy(); if (sharpHour.isEqual(other2Floor)) { System.out.println("Matching sharp hour: " + other2); }
DateTime dt = new DateTime(1385577373517L, DateTimeZone.UTC); // Prints 2013-11-27T18:36:13.517Z System.out.println(dt); // Prints 2013-11-27T18:36:00.000Z (Floor rounded to a minute) System.out.println(dt.minuteOfDay().roundFloorCopy()); // Prints 2013-11-27T18:30:00.000Z (Rounded to custom minute Window) int windowMinutes = 10; System.out.println( dt.withMinuteOfHour((dt.getMinuteOfHour() / windowMinutes) * windowMinutes).minuteOfDay().roundFloorCopy() ); SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("m"); String minute = DATE_FORMAT.format(dt.toDate()); String minString = "" + ((int)Math.round(Integer.parseInt(minute)/10)) * 10; System.out.println("Result: " + minString);