-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
8, 11, 15
ADDITIONAL SYSTEM INFORMATION :
JVMs Tested:
java version "1.8.0_172"
Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
OSes Tested:
Ubuntu 16.04.6 LTS x64
macOS Mojave 10.14.3
Red Hat Enterprise Linux Server release 6.8 (Santiago) x64
Red Hat Enterprise Linux Server release 7.5 (Maipo) x64
A DESCRIPTION OF THE PROBLEM :
When serializing the date string "0018-09-05 00:00:00.000" in UTC to an Instant, the Instant is for "0018-09-03T00:00:00Z", which has the wrong day number.
This inconsistency does not occur when using the JodaTime library.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
echo 'import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
public class Test {
public static void main(String[] args) throws ParseException {
String timestamp = "0018-09-05 00:00:00.000";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
System.out.println(simpleDateFormat.parse(timestamp).toInstant());
System.out.println(simpleDateFormat.parse(timestamp).toInstant().toEpochMilli());
}
}' > Test.java
javac Test.java
java Test
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
-61577798400000
0018-09-05T00:00:00.000Z
ACTUAL -
0018-09-03T00:00:00Z
-61577971200000
---------- BEGIN SOURCE ----------
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
public class Test {
public static void main(String[] args) throws ParseException {
String timestamp = "0018-09-05 00:00:00.000";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
System.out.println(simpleDateFormat.parse(timestamp).toInstant());
System.out.println(simpleDateFormat.parse(timestamp).toInstant().toEpochMilli());
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
The following code using JodaTime produces the correct result:
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
...
DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSS").withZoneUTC();
DateTime date = DateTime.parse("0018-09-05 00:00:00.000", fmt);
System.out.println(date.toInstant().getMillis());
System.out.println(date.toInstant());
FREQUENCY : always
JVMs Tested:
java version "1.8.0_172"
Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)
OSes Tested:
Ubuntu 16.04.6 LTS x64
macOS Mojave 10.14.3
Red Hat Enterprise Linux Server release 6.8 (Santiago) x64
Red Hat Enterprise Linux Server release 7.5 (Maipo) x64
A DESCRIPTION OF THE PROBLEM :
When serializing the date string "0018-09-05 00:00:00.000" in UTC to an Instant, the Instant is for "0018-09-03T00:00:00Z", which has the wrong day number.
This inconsistency does not occur when using the JodaTime library.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
echo 'import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
public class Test {
public static void main(String[] args) throws ParseException {
String timestamp = "0018-09-05 00:00:00.000";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
System.out.println(simpleDateFormat.parse(timestamp).toInstant());
System.out.println(simpleDateFormat.parse(timestamp).toInstant().toEpochMilli());
}
}' > Test.java
javac Test.java
java Test
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
-61577798400000
0018-09-05T00:00:00.000Z
ACTUAL -
0018-09-03T00:00:00Z
-61577971200000
---------- BEGIN SOURCE ----------
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.TimeZone;
public class Test {
public static void main(String[] args) throws ParseException {
String timestamp = "0018-09-05 00:00:00.000";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
System.out.println(simpleDateFormat.parse(timestamp).toInstant());
System.out.println(simpleDateFormat.parse(timestamp).toInstant().toEpochMilli());
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
The following code using JodaTime produces the correct result:
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
...
DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.SSS").withZoneUTC();
DateTime date = DateTime.parse("0018-09-05 00:00:00.000", fmt);
System.out.println(date.toInstant().getMillis());
System.out.println(date.toInstant());
FREQUENCY : always