Example usage for java.time Instant ofEpochSecond

List of usage examples for java.time Instant ofEpochSecond

Introduction

In this page you can find the example usage for java.time Instant ofEpochSecond.

Prototype

public static Instant ofEpochSecond(long epochSecond) 

Source Link

Document

Obtains an instance of Instant using seconds from the epoch of 1970-01-01T00:00:00Z.

Usage

From source file:Main.java

public static void main(String[] args) {
    Instant instant = Instant.ofEpochSecond(123123123123L);
    System.out.println(instant.getEpochSecond());

}

From source file:Main.java

public static void main(String[] args) {
    Instant firstInstant = Instant.ofEpochSecond(1234881180);

    System.out.println(firstInstant);
}

From source file:Main.java

public static void main(String[] args) {
    Instant instance9 = Instant.ofEpochSecond(9);
    System.out.println(instance9);

    instance9 = Instant.ofEpochSecond(-9);
    System.out.println(instance9);
}

From source file:Main.java

public static void main(String[] args) {
    Instant firstInstant = Instant.ofEpochSecond(1294881180);
    Instant secondInstant = Instant.ofEpochSecond(1294708260);

    Duration between = Duration.between(firstInstant, secondInstant);

    System.out.println(between);//  w w w . j  a  v a  2s .co  m
}

From source file:Main.java

public static void main(String[] args) {
    Instant firstInstant = Instant.ofEpochSecond(1294881180);
    Instant secondInstant = Instant.ofEpochSecond(1294708260);

    Duration between = Duration.between(firstInstant, secondInstant);

    System.out.println(between);// ww w .j  av a 2 s .  com

    long seconds = between.getSeconds();

    long absoluteResult = between.abs().toMinutes();

}

From source file:Main.java

public static void main(String[] args) {
    // Instant is useful for generating a time stamp to represent machine time.
    Instant timestamp = Instant.now();

    // How many seconds have occurred since the beginning of the Java epoch.
    long secondsFromEpoch = Instant.ofEpochSecond(0L).until(Instant.now(), ChronoUnit.SECONDS);

    System.out.println(secondsFromEpoch);
}

From source file:Main.java

public static LocalDateTime getDateTimeFromTimestamp(long timestamp) {
    if (timestamp == 0)
        return null;
    return LocalDateTime.ofInstant(Instant.ofEpochSecond(timestamp), TimeZone.getDefault().toZoneId());
}

From source file:org.eclipse.smarthome.binding.weatherunderground.internal.json.WeatherUndergroundJsonUtils.java

/**
 * Convert a string representing an Epoch value into a Calendar object
 *
 * @param value the Epoch value as a string
 *
 * @return the ZonedDateTime object representing the date and time of the Epoch
 *         or null in case of conversion error
 *///ww  w .  j  a va 2  s .  c om
public static ZonedDateTime convertToZonedDateTime(String value) {
    if (isValid(value)) {
        try {
            Instant epochSeconds = Instant.ofEpochSecond(Long.valueOf(value));
            return ZonedDateTime.ofInstant(epochSeconds, TimeZone.getDefault().toZoneId());
        } catch (DateTimeException e) {
            LoggerFactory.getLogger(WeatherUndergroundJsonUtils.class)
                    .debug("Cannot convert {} to ZonedDateTime", value);
        }
    }

    return null;
}

From source file:fi.luontola.cqrshotel.JsonSerializationTest.java

@Test
public void Instant_format() throws JsonProcessingException {
    assertThat(objectMapper.writeValueAsString(Instant.ofEpochSecond(0)), is("\"1970-01-01T00:00:00Z\""));
}

From source file:se.sawano.java.security.otp.rfc6238.ReferenceDataRepository.java

private static ReferenceData createData(final String line) {
    final StringTokenizer tokenizer = new StringTokenizer(line, "|");
    tokenizer.nextToken(); // Remove first blank token

    return new ReferenceData.Builder().withTime(Instant.ofEpochSecond(Long.valueOf(next(tokenizer))))
            .withUtcTime(next(tokenizer)).withHexTime(next(tokenizer)).withTotp(next(tokenizer))
            .withMode(ReferenceData.Mode.fromCode(next(tokenizer))).createTestData();

}