subtract LocalDateTime - Java java.time

Java examples for java.time:LocalDateTime

Description

subtract LocalDateTime

Demo Code


//package com.java2s;

import java.time.LocalDateTime;
import java.time.ZoneOffset;

public class Main {
    public static LocalDateTime subtract(LocalDateTime localDateTime,
            long delta) {
        return add(localDateTime, -delta);
    }/*from w w w.  ja va2s . c o  m*/

    public static LocalDateTime add(LocalDateTime localDateTime, long delta) {
        return convertUnixToLocalDateTime(localDateTime
                .toEpochSecond(ZoneOffset.UTC) + delta);
    }

    /**
     * 
     * @param unixTime expressed in seconds since January 1 1970 GMT, standard epoch
     * @return 
     */
    public static LocalDateTime convertUnixToLocalDateTime(long unixTime) {
        return LocalDateTime.ofEpochSecond(unixTime, 0, ZoneOffset.UTC);
    }
}

Related Tutorials