jdk/src/java.base/share/classes/java/time/Instant.java
changeset 29230 19c7760bc203
parent 25859 3317bb8137f4
child 32041 a7acd5afbd27
equal deleted inserted replaced
29229:522667854295 29230:19c7760bc203
     1 /*
     1 /*
     2  * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
  1227      *
  1227      *
  1228      * @return the number of milliseconds since the epoch of 1970-01-01T00:00:00Z
  1228      * @return the number of milliseconds since the epoch of 1970-01-01T00:00:00Z
  1229      * @throws ArithmeticException if numeric overflow occurs
  1229      * @throws ArithmeticException if numeric overflow occurs
  1230      */
  1230      */
  1231     public long toEpochMilli() {
  1231     public long toEpochMilli() {
  1232         long millis = Math.multiplyExact(seconds, 1000);
  1232         if (seconds < 0 && nanos > 0) {
  1233         return millis + nanos / 1000_000;
  1233             long millis = Math.multiplyExact(seconds+1, 1000);
       
  1234             long adjustment = nanos / 1000_000 - 1000;
       
  1235             return millis + adjustment;
       
  1236         } else {
       
  1237             long millis = Math.multiplyExact(seconds, 1000);
       
  1238             return millis + nanos / 1000_000;
       
  1239         }
  1234     }
  1240     }
  1235 
  1241 
  1236     //-----------------------------------------------------------------------
  1242     //-----------------------------------------------------------------------
  1237     /**
  1243     /**
  1238      * Compares this instant to the specified instant.
  1244      * Compares this instant to the specified instant.