• Post Reply Bookmark Topic Watch Topic
  • New Topic

Trying to work out flight times from London to New York  RSS feed

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So far this is the code I have which covers the time difference between the two and the timezone conversion. However I am struggling to set the custom date I have and to make it add 7 1/2 hours to it (the flight time between the two) so it can show how long the flight is, of which then showing the local time of New York once the flight is over.
 
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the issue you have?
What result are you seeing, and what result are you expecting?

One thing I will say is that this would probably be a lot easier using the new java.time classes, if you have Java 8.
 
orry kaplan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:What is the issue you have?
What result are you seeing, and what result are you expecting?

One thing I will say is that this would probably be a lot easier using the new java.time classes, if you have Java 8.


im just unsure about how to add the flight time of 7 1|2 hours to the london timedate to then show the US local
 
orry kaplan
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
orry kaplan wrote:So far this is the code I have which covers the time difference between the two and the timezone conversion. However I am struggling to set the custom date I have and to make it add 7 1/2 hours to it (the flight time between the two) so it can show how long the flight is, of which then showing the local time of New York once the flight is over.



this is my secondary attempt however what i am doing is not presenting the actual time in the output from the flights and im not sure why?

 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I say, this is where the new time stuff would be useful, but anyway...how many milliseconds in 7 1/2 hours?

You've already calculated from millis to hours there.
So get the flight time in millis and add it to the initial date.getTime and create a new Date from that value.

Note, a Date object represents millis from 1/1/1970 (or thereabouts).
It does not have a Timezone as such (it's UTC).

Anyway, you will then have two Date objects.
One with the takeoff time (your original 'date'), and a new one with the landing time.

You can then set display them in whatever timezones you want.
 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We cross posted there.

OK, using the new stuff.

Create a ZonedDateTime for the start timezone and the correct date and time.

Use the withZoneSameInstant method to create a new ZonedDateTime from this first one, with the destination timezone.  That gives you your target.  Then use the addXXX methods to get a ZonedDateTime with the 7.5 hours added.

There may be a slightly quicker way using a Duration.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!