List of usage examples for java.time LocalDateTime now
public static LocalDateTime now()
From source file:Main.java
public static void main(String[] args) { LocalDate february20th = LocalDate.of(2014, Month.FEBRUARY, 20); System.out.println(february20th); System.out.println(LocalDate.from(february20th.plus(15, ChronoUnit.YEARS))); // 2029-02-20 System.out.println(LocalDate.MAX); System.out.println(LocalDate.MIN); System.out.println(LocalTime.MIDNIGHT); // 00:00 System.out.println(LocalTime.NOON); // 12:00 System.out.println(LocalTime.of(23, 12, 30, 500)); // 23:12:30.000000500 System.out.println(LocalTime.now()); // 00:40:34.110 System.out.println(LocalTime.ofSecondOfDay(11 * 60 * 60)); // 11:00 System.out.println(LocalTime.from(LocalTime.MIDNIGHT.plusHours(4))); // 04:00 System.out.println(LocalTime.MIN); System.out.println(LocalTime.MAX); System.out.println(LocalDateTime.of(2014, 2, 15, 12, 30, 50, 200)); // 2014-02-15T12:30:50.000000200 System.out.println(LocalDateTime.now()); // 2014-02-28T17:28:21.002 System.out.println(LocalDateTime.from(LocalDateTime.of(2014, 2, 15, 12, 30, 40, 500).plusHours(19))); // 2014-02-16T07:30:40.000000500 System.out.println(LocalDateTime.MAX); }
From source file:com.doctor.other.concurrent_hash_map_based_table.ConcurrentHashMapBasedTable.java
public static void main(String[] args) throws InterruptedException { ConcurrentHashMapBasedTable<Long> table = new ConcurrentHashMapBasedTable<>(); // table.startExpire(); table.put("row", "col", LocalDateTime.now().minusHours(4L).format(Util.timeFormatter), Uuid.getId()); table.put("row", "col", LocalDateTime.now().format(Util.timeFormatter), Uuid.getId()); table.put("row", "col", LocalDateTime.now().format(Util.timeFormatter), Uuid.getId()); table.put("row", "col", LocalDateTime.now().format(Util.timeFormatter), Uuid.getId()); table.put("row", "col", LocalDateTime.now().format(Util.timeFormatter), Uuid.getId()); table.put("row1", "col", LocalDateTime.now().format(Util.timeFormatter), Uuid.getId()); table.put("row1", "col2", LocalDateTime.now().format(Util.timeFormatter), Uuid.getId()); table.put("row", "col", LocalDateTime.now().plusDays(1).format(Util.timeFormatter), Uuid.getId()); System.out.println(table);//from w w w . j ava2s . c o m // System.out.println(table.getSumForRowKey("row")); // System.out.println(table.getSumForRowKey("row1")); // System.out.println(table.getSumForRowKey("row1s")); // System.out.println(table.getSumForRowColumnKey("row", "col")); // System.out.println(table.getSumForRowColumnKey("row1", "col")); // System.out.println(table.getSumForRowColumnKey("row1", "col2")); // table.startExpire(); // TimeUnit.SECONDS.sleep(5L); // table.closeExpire(); // // System.out.println(table); // TimeUnit.SECONDS.sleep(5L); // List<Long> list = table.get("row", "col", LocalDateTime.now().format(Util.timeFormatter)); // System.out.println(list); // // List<Long> list2 = table.get("row", "col"); // System.out.println(list2); table.clear(); System.out.println("" + table); }
From source file:org.g_node.micro.commons.AppUtils.java
/** * Return time stamp formatted corresponding to input dateTimeFormatPattern pattern. * @param dateTimeFormatPattern Input dateTimeFormatPattern pattern. * Use {@link DateTimeFormatter} pattern conventions. * @return Formatted timestamp.//from w ww. j a v a 2 s . com */ public static String getTimeStamp(final String dateTimeFormatPattern) { return LocalDateTime.now().format(DateTimeFormatter.ofPattern(dateTimeFormatPattern)); }
From source file:org.openmastery.time.LocalDateTimeService.java
public static LocalDateTime nowTruncateToSeconds() { return LocalDateTime.now().truncatedTo(ChronoUnit.SECONDS); }
From source file:Main.java
/** * Gets the next or same closest date from the specified days in * {@code daysOfWeek List} at specified {@code hour} and {@code min}. * // w ww . j a v a 2 s .c om * @param daysOfWeek * the days of week * @param hour * the hour * @param min * the min * @return the next or same date from the days of week at specified time * @throws IllegalArgumentException * if the {@code daysOfWeek List} is empty. */ public static LocalDateTime getNextClosestDateTime(List<DayOfWeek> daysOfWeek, int hour, int min) throws IllegalArgumentException { if (daysOfWeek.isEmpty()) { throw new IllegalArgumentException("daysOfWeek should not be empty."); } final LocalDateTime dateNow = LocalDateTime.now(); final LocalDateTime dateNowWithDifferentTime = dateNow.withHour(hour).withMinute(min).withSecond(0); // @formatter:off return daysOfWeek.stream().map(d -> dateNowWithDifferentTime.with(TemporalAdjusters.nextOrSame(d))) .filter(d -> d.isAfter(dateNow)).min(Comparator.naturalOrder()) .orElse(dateNowWithDifferentTime.with(TemporalAdjusters.next(daysOfWeek.get(0)))); // @formatter:on }
From source file:ScheduledTask.java
public void run() { LocalDateTime currentDateTime = LocalDateTime.now(); System.out.println("Task #" + this.taskId + " ran at " + currentDateTime); }
From source file:net.dv8tion.discord.util.GoogleSearch.java
public static void setup(String googleApiKey) { GOOGLE_API_KEY = googleApiKey; dayStartTime = LocalDateTime.now(); }
From source file:org.jgrades.rest.admin.accounts.UserSpecificationsBuilder.java
private static LocalDateTime endDateTime(LocalDateTime dateTime) { return dateTime == null ? LocalDateTime.now() : dateTime; }
From source file:ch.wisv.areafiftylan.utils.ResponseEntityBuilder.java
/** * Create a standard response for all requests to the API * * @param httpStatus The HTTP Status of the response * @param httpHeaders Optional Http Headers for the response. * @param message The message in human readable String format * @param object Optional object related to the request (like a created User) * * @return The ResponseEntity in standard Area FiftyLAN format. *//* w ww . ja v a 2s .c o m*/ public static ResponseEntity<?> createResponseEntity(HttpStatus httpStatus, HttpHeaders httpHeaders, String message, Object object) { Map<String, Object> responseBody = new LinkedHashMap<>(); responseBody.put("status", httpStatus.toString()); responseBody.put("timestamp", LocalDateTime.now().toString()); responseBody.put("message", message); responseBody.put("object", object); if (httpHeaders == null) { httpHeaders = new HttpHeaders(); } return new ResponseEntity<>(responseBody, httpHeaders, httpStatus); }
From source file:net.ceos.project.poi.annotated.bean.MultiTypeObjectBuilder.java
/** * Create a MultiTypeObject for tests./*from w ww .j av a2 s . c om*/ * * @return the {@link MultiTypeObject} */ public static MultiTypeObject buildMultiTypeObject(int multiplier) { MultiTypeObject toValidate = new MultiTypeObject(); toValidate.setDateAttribute(new Date()); toValidate.setLocalDateAttribute(LocalDate.now()); toValidate.setLocalDateTimeAttribute(LocalDateTime.now()); toValidate.setStringAttribute("some string"); toValidate.setIntegerAttribute(46 * multiplier); toValidate.setDoubleAttribute(Double.valueOf("25.3") * multiplier); toValidate.setLongAttribute(Long.valueOf("1234567890") * multiplier); toValidate.setBooleanAttribute(Boolean.FALSE); /* create sub object Job */ Job job = new Job(); job.setJobCode(0005); job.setJobFamily("Family Job Name"); job.setJobName("Job Name"); toValidate.setJob(job); toValidate.setIntegerPrimitiveAttribute(121 * multiplier); toValidate.setDoublePrimitiveAttribute(44.6 * multiplier); toValidate.setLongPrimitiveAttribute(987654321L * multiplier); toValidate.setBooleanPrimitiveAttribute(true); /* create sub object AddressInfo */ AddressInfo ai = new AddressInfo(); ai.setAddress("this is the street"); ai.setNumber(99); ai.setCity("this is the city"); ai.setCityCode(70065); ai.setCountry("This is a Country"); toValidate.setAddressInfo(ai); toValidate.setFloatAttribute(14.765f * multiplier); toValidate.setFloatPrimitiveAttribute(11.1125f * multiplier); toValidate.setUnitFamily(UnitFamily.COMPONENTS); toValidate.setBigDecimalAttribute(BigDecimal.valueOf(24.777).multiply(BigDecimal.valueOf(multiplier))); toValidate.setShortAttribute((short) 17); toValidate.setShortPrimitiveAttribute((short) 4); // TODO add new fields below return toValidate; }