Example usage for java.time LocalDateTime now

List of usage examples for java.time LocalDateTime now

Introduction

In this page you can find the example usage for java.time LocalDateTime now.

Prototype

public static LocalDateTime now() 

Source Link

Document

Obtains the current date-time from the system clock in the default time-zone.

Usage

From source file:br.edu.ifpb.padroes.projeto.sisbiblioteca.mail.EmprestimoEmail.java

public LocalDateTime sendEmail(Emprestimo emprestimo) throws EmailException {

    SimpleEmail simpleEmail = createSimpleEmail();
    simpleEmail.setSubject("SisBiblioteca - Notificao - Emprstimo [ID]: " + emprestimo.getId());
    simpleEmail.setMsg("Ol, " + emprestimo.getAluno().getNome() + ", \n"
            + "Falta apenas 1 dia para finalizao do Emprstimo do livro "
            + emprestimo.getLivro().getTitulo() + "!\n"
            + "Por favor, proceder com a devoluo do livro at a data "
            + DateUtils.formatToBrazilPattern(emprestimo.getEndDate()));
    simpleEmail.setAuthentication("sysagenda@gmail.com", "Sisagendapoo");
    simpleEmail.setFrom("sysagenda@gmail.com", "sisBiblioteca");
    simpleEmail.addTo(emprestimo.getAluno().getEmail());
    simpleEmail.send();//w  w  w  .  j a va2 s.  c o  m

    return LocalDateTime.now();
}

From source file:org.springsource.restbucks.payment.Payment.java

/**
 * Creates a new {@link Payment} referring to the given {@link Order}.
 * //from  w  w w .j a v  a  2 s.c om
 * @param order must not be {@literal null}.
 */
public Payment(Order order) {

    Assert.notNull(order);
    this.order = order;
    this.paymentDate = LocalDateTime.now();
}

From source file:com.serphacker.serposcope.db.google.GoogleRankDBH2IT.java

@Test
public void testUrlTooLongDatabase() {

    Group grp = new Group(Group.Module.GOOGLE, "grp");
    baseDB.group.insert(grp);/* w  w w. j a va  2 s  .  co m*/

    GoogleSearch search = new GoogleSearch("keyword");
    googleDB.search.insert(Arrays.asList(search), grp.getId());

    GoogleTarget target = new GoogleTarget(grp.getId(), "name", GoogleTarget.PatternType.REGEX, "pattern");
    googleDB.target.insert(Arrays.asList(target));

    Run run = new Run(Run.Mode.CRON, Group.Module.GOOGLE, LocalDateTime.now().withNano(0));
    baseDB.run.insert(run);

    String longUrl = StringUtils.repeat("a", 256);

    GoogleRank rank = new GoogleRank(run.getId(), grp.getId(), target.getId(), search.getId(), 1, 2, longUrl);
    assertTrue(googleDB.rank.insert(rank));

    GoogleBest best = new GoogleBest(grp.getId(), target.getId(), search.getId(), 1, LocalDateTime.MIN,
            longUrl);
    assertTrue(googleDB.rank.insertBest(best));
}

From source file:io.yields.math.framework.kpi.ExplorerDAO.java

public static void save(Explorer<?> explorer) {
    String group = explorer.getGroup();
    if (StringUtils.isBlank(group)) {
        group = NO_GROUP;//w  w w  . j a va2  s.c o  m
    }
    File destinationFolder = getRootFolder(group);

    if (!destinationFolder.exists()) {
        try {
            forceMkdir(destinationFolder);
        } catch (IOException ioe) {
            throw new IllegalStateException(
                    format("Destination folder for data export could not be created at %s",
                            destinationFolder.getAbsolutePath()),
                    ioe);
        }
    }

    if (!destinationFolder.isDirectory()) {
        throw new IllegalStateException(format("Destination path for data export %s is not a folder",
                destinationFolder.getAbsolutePath()));
    }

    if (!destinationFolder.canWrite()) {
        throw new IllegalStateException(format("Destination folder for data export %s is not writable",
                destinationFolder.getAbsolutePath()));
    }

    String fileName = explorer.getName().replaceAll("[^a-zA-Z0-9]", "_") + "_"
            + DATE_TIME_FORMATTER.format(LocalDateTime.now());

    File csvDestinationFile = new File(destinationFolder, fileName + "." + FILE_SUFFIX_CSV);
    csvExporter.export(explorer, csvDestinationFile);

    File jsonDestinationFile = new File(destinationFolder, fileName + "." + FILE_SUFFIX_JSON);
    jsonExporter.export(explorer, jsonDestinationFile);

}

From source file:org.openapis.example.manual.AbstractResource.java

@POST
@Path("/many")
public PaginatedList<T> createMany(PaginatedList<T> list) {
    LocalDateTime now = LocalDateTime.now();
    String user = getUserName();/*from w  w w  . j  a va 2 s  .c o  m*/

    List<T> entities = list.getItems().stream().map(entity -> {
        if (entity instanceof Auditable) {
            Auditable auditable = (Auditable) entity;
            auditable.setCreatedBy(user);
            auditable.setCreatedDate(now);
            auditable.setModifiedBy(user);
            auditable.setModifiedDate(now);
        }

        return entity;
    }).collect(toList());

    return new PaginatedList<T>(service.insert(entities));
}

From source file:org.cyberjos.jcconf2014.node.CloudNodeImpl.java

/**
 * Constructor.//  w  w  w  .j a  v  a 2s.c  om
 */
public CloudNodeImpl() {
    this.nodeName = "Node-" + LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd-HHmmss-SSS"));

    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        logger.info("Shutdown hook is invoked.");
        this.deactivate();
        try {
            Thread.currentThread().join();
        } catch (final Exception ex) {
            logger.warn("An error is occurred while shuting down.", ex);
        }
        Hazelcast.shutdownAll();
    }));
}

From source file:org.jbb.lib.eventbus.JbbEventBus.java

@Override
public void post(Object event) {
    if (event instanceof JbbEvent) {
        JbbEvent jbbEvent = (JbbEvent) event;
        includeMetaData(jbbEvent);//from  www. j a va2 s .  com
        validateEvent(jbbEvent);
        jbbEvent.setPublishDateTime(LocalDateTime.now());
        super.post(event);
        jbbEventMetrics.incrementMetricCounter(jbbEvent);
    } else {
        throw new IllegalArgumentException(
                "You should post only JbbEvents through JbbEventBus, not: " + event.getClass());
    }
}

From source file:io.hawkcd.agent.utilities.ReportAppender.java

private static String getTimeStamp() {
    // e.g. [10:51:50:564]:
    LocalDateTime now = LocalDateTime.now();
    String format = String.format("[%02d:%02d:%02d]:", now.getHour(), now.getMinute(), now.getSecond());
    return format;
}

From source file:com.esri.geoevent.test.tools.RunTcpInTcpOutTest.java

public void send(String server, Integer port, Long numEvents, Integer rate) {
    Random rnd = new Random();
    BufferedReader br = null;/*  ww w.j  av a 2s .c  o  m*/
    LocalDateTime st = null;

    try {
        Socket sckt = new Socket(server, port);
        OutputStream os = sckt.getOutputStream();
        //PrintWriter sckt_out = new PrintWriter(os, true);

        Integer cnt = 0;

        st = LocalDateTime.now();

        Double ns_delay = 1000000000.0 / (double) rate;

        long ns = ns_delay.longValue();
        if (ns < 0) {
            ns = 0;
        }

        while (cnt < numEvents) {
            cnt += 1;
            LocalDateTime ct = LocalDateTime.now();
            String dtg = ct.toString();
            Double lat = 180 * rnd.nextDouble() - 90.0;
            Double lon = 360 * rnd.nextDouble() - 180.0;
            String line = "RandomPoint," + cnt.toString() + "," + dtg + ",\"" + lon.toString() + ","
                    + lat.toString() + "\"," + cnt.toString() + "\n";

            final long stime = System.nanoTime();

            long etime = 0;
            do {
                etime = System.nanoTime();
            } while (stime + ns >= etime);

            if (cnt % 1000 == 0) {
                //System.out.println(cnt);
            }

            //sckt_out.write(line);
            os.write(line.getBytes());
            os.flush();

        }

        if (st != null) {
            LocalDateTime et = LocalDateTime.now();

            Duration delta = Duration.between(st, et);

            Double elapsed_seconds = (double) delta.getSeconds() + delta.getNano() / 1000000000.0;

            send_rate = (double) numEvents / elapsed_seconds;
        }

        //sckt_out.close();
        sckt.close();
        os = null;
        //sckt_out = null;

    } catch (Exception e) {
        System.err.println(e.getMessage());
        send_rate = -1.0;
    } finally {
        try {
            br.close();
        } catch (Exception e) {
            //
        }

        this.send_rate = send_rate;

    }

}

From source file:no.asgari.civilization.server.model.Draw.java

public Draw(String pbfId, String playerId) {
    this.pbfId = pbfId;
    this.playerId = playerId;

    created = LocalDateTime.now();
}