List of usage examples for java.time LocalDateTime now
public static LocalDateTime now(Clock clock)
From source file:Main.java
public static void main(String[] args) { //Current date in "Asia/Kolkata" LocalDateTime todayKolkata = LocalDateTime.now(ZoneId.of("Asia/Kolkata")); System.out.println("Current Date in IST=" + todayKolkata); }
From source file:Main.java
public static void main(String[] args) { // Current Time Clock clock = Clock.systemUTC(); System.out.println(Clock.systemDefaultZone()); LocalDateTime dateAndTime = LocalDateTime.now(clock); System.out.println(dateAndTime); System.out.println(LocalDateTime.now()); }
From source file:org.jbb.security.impl.lockout.DateTimeProvider.java
public static LocalDateTime now() { return LocalDateTime.now(clock); }
From source file:com.example.db.Message.java
public static Message createNew(final User user, final String text) { final long id = System.currentTimeMillis(); return new Message(id, user.getId(), text, LocalDateTime.now(ZoneId.of("UTC"))); }
From source file:com.example.db.User.java
public static User createNew(final String username, final String password) { final String id = UUID.randomUUID().toString(); return new User(id, username, password, UserRole.forNormalUser(), LocalDateTime.now(ZoneId.of("UTC"))); }
From source file:com.example.IdGenerator.java
public long generateLong() { final LocalDateTime now = LocalDateTime.now(clock); final Duration duration = Duration.between(BASE, now); final int high = (int) duration.getSeconds(); final int low = duration.getNano(); final byte[] hbs = ByteBuffer.allocate(4).putInt(high).array(); final byte[] lbs = ByteBuffer.allocate(4).putInt(low).array(); final byte[] bytes = new byte[8]; System.arraycopy(hbs, 0, bytes, 0, 4); System.arraycopy(lbs, 0, bytes, 4, 4); final ByteBuffer buffer = ByteBuffer.allocate(8).put(bytes, 0, 8); buffer.flip();//from w ww . j a v a 2s .com return buffer.getLong(); }
From source file:com.khartec.waltz.model.accesslog.AccessLog.java
@Value.Default public LocalDateTime createdAt() { return LocalDateTime.now(ZoneId.of("UTC")); }
From source file:h2backup.BackupFileService.java
public Path backupDatabase(BackupMethod method, String directory, String filePrefix, String dateTimeFormatPattern) { try {// w ww.ja va2s . co m String fileNameWithoutExt = filePrefix + "_" + DateTimeFormatter.ofPattern(dateTimeFormatPattern).format(LocalDateTime.now(clock)) + "_" + method.getFileSuffix(); final Path path = Paths.get(directory, fileNameWithoutExt + ZIP_EXTENSION); final Path tmpPath = Paths.get(directory, fileNameWithoutExt + TMP_SUFFIX + ZIP_EXTENSION); log.info("Starting backup to file {} using {} method", tmpPath, method); method.getStrategy().backupDatabase(dataSource, tmpPath.toString()); if (Files.exists(path) && FileUtils.contentEquals(tmpPath.toFile(), path.toFile())) { log.info("Deleting backup {} because it is identical to previous backup {}", tmpPath, path); Files.delete(tmpPath); return null; } int maxIndex = 0; do { maxIndex++; } while (Files.exists(Paths.get(directory, fileNameWithoutExt + "_" + maxIndex + ZIP_EXTENSION))); for (int index = maxIndex; index >= 1; index--) { Path oldPath = Paths.get(directory, fileNameWithoutExt + (index > 1 ? "_" + (index - 1) : "") + ZIP_EXTENSION); Path newPath = Paths.get(directory, fileNameWithoutExt + "_" + index + ZIP_EXTENSION); if (Files.exists(oldPath)) { log.debug("Moving file {} to {}", oldPath, newPath); Files.move(oldPath, newPath); } } Files.move(tmpPath, path); return path; } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.kazuki43zoo.jpetstore.service.OrderService.java
@Transactional public void createOrder(Order order, Account account) { order.setUsername(account.getUsername()); int orderId = generateOrderId(); order.setOrderId(orderId);//w ww . ja v a 2 s .c o m order.setOrderDate(LocalDateTime.now(clock)); order.setCourier("UPS"); order.setLocale("CA"); order.setStatus("P"); orderMapper.insertOrder(order); orderMapper.insertOrderStatus(order); order.getLines().forEach(x -> { itemMapper.updateInventoryQuantity(x.getItemId(), x.getQuantity()); x.setOrderId(orderId); orderMapper.insertOrderLine(x); }); }
From source file:com.github.akiraly.db4j.uow.UowNotPersistedIfNotNeededTest.java
@Test(timeout = 5000) public void testUowNotPersistedIfNotNeeded() { final String uow1User = "u300"; Uow uow1 = new Uow(uow1User); final Foo foo = new Foo("bar", LocalDateTime.now(ZoneOffset.UTC)); EntityWithLongId<Foo> fooWithId = transactionTemplate.execute(s -> { FooDao fooDao = fooDaoFactory.newDao(); UowDao uowDao = uowDaoFactory.newDao(); assertEquals(0, fooDao.count()); assertEquals(0, uowDao.count()); EntityWithLongId<Foo> result = fooDao.lazyPersist(foo); assertEquals(1, result.getId()); assertEquals(1, fooDao.count()); assertEquals(0, uowDao.count()); return result; });//from w w w. ja v a 2s .c om transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { FooDao fooDao = fooDaoFactory.newDao(); assertEquals(1, fooDao.count()); assertEquals("bar", fooDao.lazyFind(fooWithId.getId()).getEntity().getBar()); assertEquals(1, fooDao.deleteAll()); } }); transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { UowDao uowDao = uowDaoFactory.newDao(); AuditedFooDao auditedFooDao = auditedFooDaoFactory.newDao(uowDao); assertEquals(0, uowDao.count()); EntityWithLongId<Uow> uowWithId1 = uowDao.lazyPersist(uow1); AuditedFoo auditedFoo = new AuditedFoo("bar", uowWithId1); EntityWithLongId<AuditedFoo> fooWithId = auditedFooDao.lazyPersist(auditedFoo); assertEquals("bar", fooWithId.getEntity().getBar()); assertEquals(0, uowDao.count()); } }); transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { UowDao uowDao = uowDaoFactory.newDao(); AuditedFooUuidDao auditedFooUuidDao = auditedFooUuidDaoFactory.newDao(uowDao); assertEquals(0, uowDao.count()); EntityWithLongId<Uow> uowWithId1 = uowDao.lazyPersist(uow1); AuditedFoo auditedFoo = new AuditedFoo("bar", uowWithId1); EntityWithUuid<AuditedFoo> fooWithId = auditedFooUuidDao.lazyPersist(auditedFoo); assertEquals("bar", fooWithId.getEntity().getBar()); assertEquals(0, uowDao.count()); } }); }