Example usage for java.time.temporal ChronoField MILLI_OF_SECOND

List of usage examples for java.time.temporal ChronoField MILLI_OF_SECOND

Introduction

In this page you can find the example usage for java.time.temporal ChronoField MILLI_OF_SECOND.

Prototype

ChronoField MILLI_OF_SECOND

To view the source code for java.time.temporal ChronoField MILLI_OF_SECOND.

Click Source Link

Document

The milli-of-second.

Usage

From source file:Main.java

public static void main(String[] args) {
    Instant instant = Instant.parse("2014-12-03T10:15:30.00Z");
    instant = instant.with(ChronoField.MILLI_OF_SECOND, 20);
    System.out.println(instant);/*from w w w . ja  va2 s.co  m*/

}

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

/**
 * Get the end of the day passed in/*from   w  w w.  j ava  2 s. c o  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;

}