Example usage for java.time OffsetDateTime now

List of usage examples for java.time OffsetDateTime now

Introduction

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

Prototype

public static OffsetDateTime now(Clock clock) 

Source Link

Document

Obtains the current date-time from the specified clock.

Usage

From source file:Main.java

public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.now(Clock.systemUTC());

    System.out.println(o);
}

From source file:Main.java

public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.now(ZoneId.systemDefault());

    System.out.println(o);
}

From source file:com.example.hello.HelloEndpoint.java

Mono<ServerResponse> hello(final ServerRequest serverRequest) {
    return ServerResponse.ok().contentType(MediaType.APPLICATION_JSON)
            .body(Mono.just(new HelloMessage("hello", OffsetDateTime.now(ZoneId.of("Z")))), HelloMessage.class);
}

From source file:de.kaiserpfalzEdv.commons.jee.spring.ServiceLogging.java

@Around("execution(* de.kaiserpfalzEdv..service..*Impl.*(..))")
public Object updateMDC(ProceedingJoinPoint joinPoint) throws Throwable {
    String id = retrieveIdFromMDCOrGenerateNewUUID(joinPoint);
    MDC.put("id", id);

    Object result;// w w  w .jav a2  s  . c o m

    if (oplog.isInfoEnabled()) {
        String serviceName = retrieveMethodNameFromSignature(joinPoint);

        OffsetDateTime start = OffsetDateTime.now(UTC);
        oplog.info("Service '{}' started. id={}, start={}", serviceName, id, start);

        result = joinPoint.proceed();

        OffsetDateTime end = OffsetDateTime.now(UTC);

        oplog.info("Service '{}' ended. id={}, start={}, duration={}",
                retrieveMethodNameFromSignature(joinPoint), id, start, Duration.between(start, end));
    } else {
        result = joinPoint.proceed();
    }

    MDC.remove("id");

    return result;
}

From source file:de.kaiserpfalzEdv.office.core.security.impl.SecurityTicket.java

public SecurityTicket(@NotNull final Account account) {
    id = UUID.randomUUID().toString();
    this.account = account;
    created = OffsetDateTime.now(TIMEZONE);
    validity = created.plusSeconds(DEFAULT_TTL);
}

From source file:de.kaiserpfalzEdv.office.core.security.impl.SecurityTicket.java

public void renew() {
    validity = OffsetDateTime.now(TIMEZONE).plusSeconds(DEFAULT_RENEWAL);
}

From source file:de.kaiserpfalzEdv.office.core.security.impl.SecurityTicket.java

public boolean isValid() {
    OffsetDateTime now = OffsetDateTime.now(TIMEZONE);

    System.out.println(validity.toString() + " is hopefully after " + now.toString());

    return validity.isAfter(now);
}

From source file:de.kaiserpfalzEdv.office.core.security.OfficeLoginTicket.java

@SuppressWarnings("deprecation")
public void markCheck() {
    setLastCheck(OffsetDateTime.now(ZoneId.of("UTC")));
}

From source file:ox.softeng.burst.services.BurstService.java

public void generateStartupMessage() {
    Message message = new Message("burst-service", "Burst Service starting\n" + version(),
            SeverityEnum.INFORMATIONAL, OffsetDateTime.now(ZoneId.of("UTC")), "Burst Service Startup");
    message.addTopic("service");
    message.addTopic("startup");
    message.addTopic("burst");
    message.addMetadata("gmc", "gel");
    message.addMetadata("burst_service_version", version());

    try {/*from  ww  w .ja  v  a  2 s  .com*/
        EntityManager entityManager = entityManagerFactory.createEntityManager();
        entityManager.getTransaction().begin();
        entityManager.merge(message);
        entityManager.getTransaction().commit();
        entityManager.close();
    } catch (HibernateException he) {
        logger.error("Could not save startup message to database: " + he.getMessage(), he);
    } catch (Exception e) {
        logger.error("Unhandled exception trying to process startup message", e);
    }
}

From source file:com.amazonaws.services.kinesis.io.StringDataExtractor.java

/**
 * {@inheritDoc}//from  w  w w .  j a  va 2s  .  c  o  m
 */
@Override
public List<AggregateData> getData(InputEvent event) throws SerializationException {
    try {
        int summaryIndex = -1;
        String dateString;
        OffsetDateTime dateValue;
        List<AggregateData> data = new ArrayList<>();

        List<List<String>> content = serialiser.toClass(event);
        for (List<String> line : content) {
            if (line != null) {
                LabelSet labels = new LabelSet();
                labels.withAlias(this.labelAttributeAlias);

                for (Integer key : this.labelIndicies) {
                    labels.put("" + key, line.get(key));
                }

                // get the unique index
                String uniqueId = null;
                if (this.usePartitionKeyForUnique) {
                    uniqueId = event.getPartitionKey();
                } else if (this.useSequenceForUnique) {
                    uniqueId = event.getSequenceNumber();
                } else {
                    if (this.uniqueIdIndex != -1) {
                        uniqueId = line.get(this.uniqueIdIndex);
                    }
                }

                // get the date value from the line
                if (this.dateValueIndex != -1) {
                    dateString = line.get(dateValueIndex);
                    if (this.dateFormat != null) {
                        dateValue = OffsetDateTime.parse(dateString, dateFormatter);
                    } else {
                        // no formatter, so treat as epoch seconds
                        try {
                            dateValue = OffsetDateTime.ofInstant(
                                    Instant.ofEpochMilli(Long.parseLong(dateString)), ZoneId.of("UTC"));
                        } catch (Exception e) {
                            LOG.error(String.format(
                                    "Unable to create Date Value element from item '%s' due to invalid format as Epoch Seconds",
                                    dateValueIndex));
                            throw new SerializationException(e);
                        }
                    }
                } else {
                    dateValue = OffsetDateTime.now(ZoneId.of("UTC"));
                }

                // get the summed values
                if (this.aggregatorType.equals(AggregatorType.SUM)) {
                    sumUpdates = new HashMap<>();

                    // get the positional sum items
                    for (int i = 0; i < summaryIndicies.size(); i++) {
                        summaryIndex = summaryIndicies.get(i);
                        try {
                            sumUpdates.put("" + summaryIndex, Double.parseDouble(line.get(summaryIndex)));
                        } catch (NumberFormatException nfe) {
                            LOG.error(String.format(
                                    "Unable to deserialise Summary '%s' due to NumberFormatException", i));
                            throw new SerializationException(nfe);
                        }
                    }
                }

                data.add(new AggregateData(uniqueId, labels, dateValue, sumUpdates));
            }
        }

        return data;
    } catch (Exception e) {
        throw new SerializationException(e);
    }

}