• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Calander object from UTC string problem

 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
My program gets a string that is already in UTC format. I need to convert it to a calendar object so I can compare it to the server time. I then compare the two in milliseconds and they are way off. But not all the time. Only when the server time passes 12:00.

Since the input string is already in UTC format, I expect the same value to be printed by the Calendar object. But it doesn't.

Sample input:
2021-09-01 12:11:10

The output looks like this
Sep 01 00:11:10 UTC 2021

 
Bartender
Posts: 1737
63
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is Calendar forced on you by circumstance?
It is high on the list of "Old Java Things to Be Avoided Wherever Possible" vs. the new time/date API's in Java 8+.
 
Jesse Silverman
Bartender
Posts: 1737
63
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tho attempting to avoid Calendar in all new code I write, I note the following from SimpleDateFormat JavaDocs:

H Hour in day (0-23) Number 0
k Hour in day (1-24) Number 24
K Hour in am/pm (0-11) Number 0
h Hour in am/pm (1-12) Number 12


Do you see what I see?
Would changing to:
"yyyy-MM-dd HH:mm:ss" help cure what is ailing you?
 
M Burke
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesse Silverman wrote:Tho attempting to avoid Calendar in all new code I write, I note the following from SimpleDateFormat JavaDocs:

H Hour in day (0-23) Number 0
k Hour in day (1-24) Number 24
K Hour in am/pm (0-11) Number 0
h Hour in am/pm (1-12) Number 12


Do you see what I see?
Would changing to:
"yyyy-MM-dd HH:mm:ss" help cure what is ailing you?



Yes Jesse, that worked. Thank you. I am on Java 7
 
Jesse Silverman
Bartender
Posts: 1737
63
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

M Burke wrote:...

Yes Jesse, that worked. Thank you. I am on Java 7



Yikes!!  I wouldn't recommend going to JODA date/time just to avoid Calendar/Date then, tho some would.

For curiosity's sake, since a lot of people like saying at Conferences, "I think we can ALL agree everyone is using at least Java 8, now" with a grin, do you have specific dependencies blocking you from Java 8 or just "Time, time!"??  I've been working to make Java 11 my "new normal" before Java 17 comes crashing down on us...
 
M Burke
Ranch Hand
Posts: 434
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesse Silverman wrote:

M Burke wrote:...

Yes Jesse, that worked. Thank you. I am on Java 7



Yikes!!  I wouldn't recommend going to JODA date/time just to avoid Calendar/Date then, tho some would.

For curiosity's sake, since a lot of people like saying at Conferences, "I think we can ALL agree everyone is using at least Java 8, now" with a grin, do you have specific dependencies blocking you from Java 8 or just "Time, time!"??  I've been working to make Java 11 my "new normal" before Java 17 comes crashing down on us...



The app is 10 years old and runs on JBoss 6. Companies do keep apps for a long time. They are expensive and if the app is not broken they don't feel compelled to replace it.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a project that still has to be written in Java 6. It's an SDK, and the last time we checked, 2% of the calls originated from a Java 6 or 7 platform (the SDK sends some headers, one of which includes the Java version). I'd love to upgrade to at least Java 8 (and even have the branch for it), but I can't...
 
Jesse Silverman
Bartender
Posts: 1737
63
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Spoor wrote:I have a project that still has to be written in Java 6. It's an SDK, and the last time we checked, 2% of the calls originated from a Java 6 or 7 platform.



Like the "Last Lousy Point" in Adventure...does checking involve sending out a Survey to Users or is it something you can get data on in some automated way?

I have ONLY worked at places where the last 2% of customers kept us supporting something like this for a Long Time.  We had a rule that we will never depend on any infrastructure that is no longer supported by the Vendor/Open-Source-Project, which I would often quote, and which actually worked for me sometimes, other times some big customer kept the dependency alive despite the Rule.
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The header values are collected, and we had a reported created that showed, for each SDK, what platforms were used. No interaction with client companies was necessary.

But if you think that this 2% Java 6/7 is bad - for PHP over half of the requests were still PHP 5.4 and 5.5. And we're talking about early 2020, when PHP 5.6 (and even 7.0 and 7.1) was already EOL.

That said, we have a lot of automated Dockerized testing, so as long as we have a Docker image that still works and development is still possible, we continue supporting these old versions.

We were able to bump the minimal Node.js and Go versions though, that was something.
 
M Burke
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do have one more question. Do I need these statements?

formatter.setTimeZone(TimeZone.getTimeZone("UTC"));  

paramCal.setTimeZone(TimeZone.getTimeZone("UTC"));
 
reply
    Bookmark Topic Watch Topic
  • New Topic