• 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

Issue in calculating time diff between DST & Non-DST time

 
Ranch Hand
Posts: 84
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Rangers,

System need to show time diff in UI between 2 dates.

E.g.
Date1 -> Meeting start time(Possibly any timezone date) -> Getting this date from external source
Date2 -> Current time of the meeting location -> Finding current time based on concern time zone id

Both date is base lined with GMT and manipulate the time diff. This approach is working fine if both dates fall under same period(DST or Non-DST)

E.g. Issue scenario

Date1 -> Nov-3 6AM (Non-DST)
Date2 -> Nov-3 1AM (DST)

Vice-versa as well...

Note : Server & Desktop can be located in any timezone

Surfing to obtain posible solutions. Even found similar thread with subject "java.util.Calendar, setTime and DST" in this forum itself but couldnt get properly

There would be effective ways to calculate the time diff to handle all the scenarios. Really appreciable if anybody suggest on this.

Thanks in advance

- Raj
 
Marshal
Posts: 79512
379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need the concept that Date does not encapsulate a date. It encapsulates how many milliseconds have elapsed since 1st January 1970. Does that information help you?…and if that code works I shall be very surprised!
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rajagopal Mani wrote:There would be effective ways to calculate the time diff to handle all the scenarios. Really appreciable if anybody suggest on this.


In addition to Campbell's wise words, have a look at ABriefHistoryOfJavaTime. Hopefully, it will give you all the information you need.

And if not, come back and tell us what you don't understand.

Winston
 
Rajagopal Mani
Ranch Hand
Posts: 84
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all thank you both..

Have gone thru the link. Really useful in which my understanding some what narrowed down on java time.

With this, have come up with a way. below the psuedo code. please correct me if anything wrong in it



- Raj
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rajagopal Mani wrote:With this, have come up with a way. below the psuedo code. please correct me if anything wrong in it


I'm sorry if this sounds harsh but, based on your original post, just about everything is wrong with the first part of your code.

Java Dates ALL have the same start point, so no conversion is required whatsoever and you DON'T need to convert them to Strings.
The interval is simply:
Math.abs( d1.getTime() - d2.getTime() );

If, on the other hand, your input "dates" are strings, then the second part of your code (from line 4 on) is very close to being correct, except that 'd1' and 'd2' will be Strings, not Dates.

Simple rule: DON'T change Java times. It's almost always wrong.

HIH

Winston
 
Rajagopal Mani
Ranch Hand
Posts: 84
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes conversion to string not required. flaw there..

Below two ways would give proper time diff to show in any location irrespective of the sever locations or time zones. Out of two ways, without baseline with GMT would be more efficient than other until dates provides proper milliseconds from epoch. please correct if anything wrong here & suggest if anymore best.


Thanks
-Raj
 
Rajagopal Mani
Ranch Hand
Posts: 84
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Please correct if any concern in above approaches

Thanks,
Raj
reply
    Bookmark Topic Watch Topic
  • New Topic