Comments (4)
Hi @divanmostert ,
System.out.println(timezone) will print some of the internal values on the underlying instance (in this case sun.util.calendar.ZoneInfo), but it will not include all the internal fields that are use to do a date calculation. We have been doing some testing and both versions will print the correct date, assuming an offset of two hours for Africa/Windhoek.
The difference you are seeing comes from JDK-8212970, where how the internal representation of timezones changed, from using the rearguard formatting to use the vanguard formatting of the timezone database. This causes ZoneInfo fields like offset to now have different values (compensated on the values of transitions, a fields that is not displayed when printing the timezone).
In any case, java.util.TimeZone is part of the specification, but sun.util.calendar.ZoneInfo is not, which means its internal behavior is subject to change. For that reason, usage of methods like toString on TimeZone is discouraged (as it will call http://hg.openjdk.java.net/jdk-updates/jdk11u/file/571c180c5106/src/java.base/share/classes/sun/util/calendar/ZoneInfo.java#l546)
Additionally, please consider using the newer java.time api with java.time.ZoneId and java.time.ZonedDateTime.
Thanks,
Prashanth
from corretto-11.
Hi @divanmostert ,
Thank you for reporting this issue. We will investigate and get back to you.
Thanks,
Prashanth
from corretto-11.
Doesn't look like a bug, closing this issue.
from corretto-11.
@davecurrie I revisited this after many moons and tracked down where I think the problem is. It is with the SimpleDateFormat class which I used for string representation.
Running the below code will result in the time also being showed as updated when in fact it was not:
`public static void main(String[] args) {
testToString(2099);
testToString(2020);
}
public static void testToString(int year) {
Calendar c = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
c.set(Calendar.YEAR, 2000);
c.set(Calendar.MONTH, 11);
c.set(Calendar.DAY_OF_MONTH, 31);
c.set(Calendar.HOUR, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.AM_PM, 1);
java.util.Date gDate = c.getTime();
DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
((SimpleDateFormat) formatter).applyPattern("MMMMMM dd, yyyy HH:mm:ss a z");
Calendar gregorianCalendar = new GregorianCalendar();
gregorianCalendar.setTimeInMillis(gDate.getTime());
gregorianCalendar.set(Calendar.YEAR, year);
System.out.println(formatter.format(gregorianCalendar.getTime()) + "("+ gregorianCalendar.getTime()+")");
}`
Result is:
December 31, 2099 13:00:00 PM GMT(Thu Dec 31 14:00:00 CAT 2099)
December 31, 2020 12:00:00 PM GMT(Thu Dec 31 14:00:00 CAST 2020
from corretto-11.
Related Issues (20)
- SIGSEGV PhiNode::Ideal(PhaseGVN*, bool)+0x98 HOT 8
- NPE in sun.awt.FontConfiguration.getVersion(...) HOT 5
- JVM Crash - Problematic frame:libjvm.so+0x79e743 HOT 1
- JVM Crash - Problematic frame:libjvm.so+0x79e743 HOT 6
- Dynamic linking zlib for Linux
- Performance issues with version 11.0.19 HOT 7
- Segfault in libnet.so at high number of open connections HOT 4
- Slow class loading when running JVM in debug mode HOT 1
- Binary scan of Corretto 11.0.20.9.1 shows clean, but libjpeg constituent shows vuln HOT 1
- EXCEPTION_ACCESS_VIOLATION (0xc0000005) HOT 2
- unrecognized jvm option
- A fatal error has been detected by the Java Runtime Environment HOT 1
- JVM Crashing during GC - Problematic frame: V [libjvm.so+0x7ffedc] G1ParCopyClosure<(G1Barrier)0, (G1Mark)1>::do_oop(unsigned int*)+0x2ec HOT 2
- questdb 7.2 run in amd64/amazoncorretto:11-alpine3.18 container HOT 3
- Listing down the various components/libraries ( sjsxp) of a given corretto release HOT 3
- Please add guidelines for building 32 bit Amazon corretto 11 JRE for the targets Linux & ARM.
- PrinterListener thread sticking around on Tomcat Context undeploy HOT 2
- Finding the unknown versions of mx4j and sjsxp HOT 3
- BOM file for coretto java rpm HOT 3
- Corretto (11.0.24.8.1) generates a SIGSEV error and kills the container. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from corretto-11.