Example usage for java.time LocalDateTime with

List of usage examples for java.time LocalDateTime with

Introduction

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

Prototype

@Override
public LocalDateTime with(TemporalField field, long newValue) 

Source Link

Document

Returns a copy of this date-time with the specified field set to a new value.

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalDateTime a = LocalDateTime.of(2014, 6, 30, 12, 01);

    LocalDateTime t = a.with(ChronoField.YEAR, 2012);

    System.out.println(t);//from  ww  w.j a  v a2 s .  c o  m
}

From source file:edu.usu.sdl.openstorefront.common.util.TimeUtil.java

/**
 * Get the end of the day passed in/*from ww w . ja  va2s . co  m*/
 *
 * @param date
 * @return end of the day or null if date was null
 */
public static Date endOfDay(Date date) {
    if (date != null) {
        Instant instant = Instant.ofEpochMilli(date.getTime());
        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
        localDateTime = localDateTime.withHour(23).withMinute(59).withSecond(59)
                .with(ChronoField.MILLI_OF_SECOND, 999);
        return new Date(localDateTime.toInstant(ZoneOffset.UTC).toEpochMilli());
    }
    return date;

}