zoneddatetime

Databse DateTime milli & nano seconds are truncated by default if its 0s while using it in java-11 using ZonedDateTime

混江龙づ霸主 提交于 2021-02-11 07:58:11
问题 I am fetching datetime from oracle db and parsing in java-11 using ZonedDateTime as below: oracle --> 1/19/2020 06:09:46.038631 PM java ZonedDateTime 0/p --> 2020-01-19T18:09:46.038631Z[UTC] oracle --> 1/19/2011 4:00:00.000000 AM java ZonedDateTime o/p --> 2011-01-19T04:00Z[UTC] (So, here the 0s are truncated by default. However, my requirement is to have consistent fixed length o/p like #1.) expected java ZonedDateTime o/p --> 2011-01-19T04:00:00.000000Z[UTC] However, I didnt find any date

For a given Date object, capture it's value relevant to GMT timezone

╄→гoц情女王★ 提交于 2021-02-05 10:39:34
问题 In my application running on Java 8, I have a Date object. The timezone for this object depends on the client's location. At one particular point, I need to convert this Date to GMT so that it could be comparable to a value that I access from the DB. I tried SimpleDateFormat and ZonedDateTime, but there's a pain-point. These API's provide me GMT time in String values, which is perfectly fine. However, once I parse it and assign it to a Date object, it is back to my local timezone! For Ex:

For a given Date object, capture it's value relevant to GMT timezone

主宰稳场 提交于 2021-02-05 10:38:29
问题 In my application running on Java 8, I have a Date object. The timezone for this object depends on the client's location. At one particular point, I need to convert this Date to GMT so that it could be comparable to a value that I access from the DB. I tried SimpleDateFormat and ZonedDateTime, but there's a pain-point. These API's provide me GMT time in String values, which is perfectly fine. However, once I parse it and assign it to a Date object, it is back to my local timezone! For Ex:

ZonedDateTime.parse() fails for exact the same string in Windows but works in Mac and Linux

时光总嘲笑我的痴心妄想 提交于 2021-02-04 07:48:27
问题 The following UnitTest is failing when being executed through IntelliJ IDE in a Windows machine (Java 11.0.9) but passes when executed in a Mac or Linux machine with the same version of Java. @Test public void rfc1123JaveTimeUtilParsing(){ final String rfc1123Pattern = "EEE, dd MMM yyyy HH:mm:ss z"; final String responseTimeStamp = "Mon, 14 Dec 2020 20:34:37 GMT"; DateTimeFormatter javaTimeDateTimeFormatter = DateTimeFormatter.ofPattern(rfc1123Pattern); ZonedDateTime javaFinalTime =

ZonedDateTime from date string in yyyy-mm-dd

牧云@^-^@ 提交于 2021-01-07 02:42:29
问题 Trying to parse a ZonedDateTime from a date string e.g '2020-08-24'. Upon using TemporalAccesor, and DateTimeFormatter.ISO_OFFSET_DATE to parse, I am getting a java.time.format.DateTimeParseException. Am I using the wrong formatter? Even tried adding 'Z' at the end of date string for it to be understood as UTC private ZonedDateTime getZonedDateTime(String dateString) { TemporalAccessor parsed = null; dateString = dateString + 'Z'; try { parsed = DateTimeFormatter.ISO_OFFSET_DATE.parse

Java - Result when compare two ZonedDateTime is not as expected

南笙酒味 提交于 2020-12-09 03:56:57
问题 I have this code : ZonedDateTime t1 = ZonedDateTime.parse("2018-04-06T10:01:00.000+03:00"); ZonedDateTime t2 = ZonedDateTime.parse("2018-04-06T10:01:00.000-03:00"); System.out.println(t1.compareTo(t2)); The result is -1. I guess it will convert both t1 and t2 to the same timezone then compare it. E.g in the first case it will (maybe) compare t1 = 2018-04-06T07:01:00.000+00:00 to t2 = 2018-04-06T13:01:00.000+00:00 This case return 1 as I expected ZonedDateTime t1 = ZonedDateTime.parse("2018-04

Java - Result when compare two ZonedDateTime is not as expected

巧了我就是萌 提交于 2020-12-09 03:56:21
问题 I have this code : ZonedDateTime t1 = ZonedDateTime.parse("2018-04-06T10:01:00.000+03:00"); ZonedDateTime t2 = ZonedDateTime.parse("2018-04-06T10:01:00.000-03:00"); System.out.println(t1.compareTo(t2)); The result is -1. I guess it will convert both t1 and t2 to the same timezone then compare it. E.g in the first case it will (maybe) compare t1 = 2018-04-06T07:01:00.000+00:00 to t2 = 2018-04-06T13:01:00.000+00:00 This case return 1 as I expected ZonedDateTime t1 = ZonedDateTime.parse("2018-04