• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Want to convert timezone (from any timezone to "America/Los_Angeles"(PST))

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi All,

I am working on multi country application, user can login from any country, now I need to convert my Date in PST time zone. Every time it will get user time zone and convert it into "America/Los_Angeles" (PST) time zone, and it will return date object with converted date.




Please help.

Regards,
Roopesh
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So what problem are you facing? Does the code work?
 
Roopesh Rana
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, this code not working, it is returning IST But I need PST time zone
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There may be other problems, but the main thing I see is that Date doesn't have a Timezone associated with it.
It's always milliseconds from the Epoch.
The display format used determines what TimeZone you see.
 
Roopesh Rana
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got some thing, but this is also giving wrong result,

 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roopesh Rana wrote:I got some thing, but this is also giving wrong result,



If the thing that is incorrect is 'theResult' then, again, it is a Date object, which has no concept of Timezone.
When you print out a Date it is formatted based on your systems Timezone by default.
 
Roopesh Rana
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Through this you can achieve date in different timezone

 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now you are using the DateTime class, which is from the Joda Time library (?), instead of java.util.Date.

Joda Time's DateTime class does have timezone information, in contrast to java.util.Date.

Note that lines 4 and 5 really have no effect, since you're not doing anything with the return values of the methods that you are calling.

When you convert the DateTime to a jav.util.Date in line 5, you will lose the timezone information again (simply because java.util.Date does not store this information), so this doesn't really help you anything.
 
It is no measure of health to be well adjusted to a profoundly sick society. -Krishnamurti Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic