Quantcast

How to convert date&time from one time zone to another?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to convert date&time from one time zone to another?

Slavoj Žižek
Hi!

I am creating an international web application where one can create an event in its own local timezone, but someone outside of this zone needs to see this date&time in it's local time zone. So basically I need to get this two questions answered:

1. How do I obtain users timezone ? (from request header ??)
2. How do I convert time and date from one time zone to another using groovy?


Thanks for answers.

Slavoj
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to convert date&time from one time zone to another?

Jeff Scott Brown
On Sun, Nov 29, 2009 at 11:33 AM, Slavoj Žižek <[hidden email]> wrote:

> Hi!
>
> I am creating an international web application where one can create an event
> in its own local timezone, but someone outside of this zone needs to see
> this date&time in it's local time zone. So basically I need to get this two
> questions answered:
>
> 1. How do I obtain users timezone ? (from request header ??)
> 2. How do I convert time and date from one time zone to another using
> groovy?
>
>

It sounds you are talking just about displaying times and dates and if
that is the case, you probably don't want to convert times and dates
from one tz to another.  You probably just want to display the date
formatted for a particular tz.  Is that correct?

If that is correct, the formatDate GSP tag should do what you want
automatically.  I think by default the formatDate tag will format in
the locale associated with the current request.

Does that help?



jb
--
Jeff Brown
SpringSource
http://www.springsource.com/

Autism Strikes 1 in 166
Find The Cause ~ Find The Cure
http://www.autismspeaks.org/

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to convert date&time from one time zone to another?

HubertChang
In reply to this post by Slavoj Žižek
Request header doesn't have the information for timezone.
Two ways to detect the client timezone, one is
    1, with GeoIP database to decide the client's timezone
    2, with a javascript to calculate the offset and the DST.
         <script> var now = new Date(); var jan1st=new Date(now.getFullYear(), 0, 1, 0, 0, 0, 0); var june1st = new Date(now.getFullYear(), 0, 1, 0, 0 ,0 0) /*calculate the offset and dst */ </script>       You can google it.
 
I use Joda-time plugin to deal with datetime.
 
Slavoj Žižek wrote
Hi!

I am creating an international web application where one can create an event
in its own local timezone, but someone outside of this zone needs to see
this date&time in it's local time zone. So basically I need to get this two
questions answered:

1. How do I obtain users timezone ? (from request header ??)
2. How do I convert time and date from one time zone to another using
groovy?


Thanks for answers.

Slavoj
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to convert date&time from one time zone to another?

Slavoj Žižek
Jeff, I am only displaying dates. So I have to store dates in database in one format but display in others. Found a pure java solution here http://snipplr.com/view/104/convert-from-one-timezone-to-another/ , but don't know how should the string parameters be formatted.
 
Hubert, I didn't find the page about joda-time very helpful, any examples to clear thing up ?




On Sun, Nov 29, 2009 at 3:32 AM, Hubert Chang <[hidden email]> wrote:

Request header doesn't have the information for timezone.
Two ways to detect the client timezone, one is
   1, with GeoIP database to decide the client's timezone
   2, with a javascript to calculate the offset and the DST.
        <script> var now = new Date();
                    var jan1st=new Date(now.getFullYear(), 0, 1, 0, 0, 0,
0);
                    var june1st = new Date(now.getFullYear(), 0, 1, 0, 0 ,0
0)
                    /*calculate the offset and dst */
         </script>
      You can google it.

I use Joda-time plugin to deal with datetime.


Slavoj Žižek wrote:
>
> Hi!
>
> I am creating an international web application where one can create an
> event
> in its own local timezone, but someone outside of this zone needs to see
> this date&time in it's local time zone. So basically I need to get this
> two
> questions answered:
>
> 1. How do I obtain users timezone ? (from request header ??)
> 2. How do I convert time and date from one time zone to another using
> groovy?
>
>
> Thanks for answers.
>
> Slavoj
>
>

--
View this message in context: http://old.nabble.com/How-to-convert-date-time-from-one-time-zone-to-another--tp26558434p26558892.html
Sent from the grails - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to convert date&time from one time zone to another?

Slavoj Žižek
i find the joda documentation very helpful, maybe I'm just gonna use it without the hibernate extension since i can convert joda datetime to jdk date.

On Sun, Nov 29, 2009 at 4:04 AM, Slavoj Žižek <[hidden email]> wrote:
Jeff, I am only displaying dates. So I have to store dates in database in one format but display in others. Found a pure java solution here http://snipplr.com/view/104/convert-from-one-timezone-to-another/ , but don't know how should the string parameters be formatted.
 
Hubert, I didn't find the page about joda-time very helpful, any examples to clear thing up ?





On Sun, Nov 29, 2009 at 3:32 AM, Hubert Chang <[hidden email]> wrote:

Request header doesn't have the information for timezone.
Two ways to detect the client timezone, one is
   1, with GeoIP database to decide the client's timezone
   2, with a javascript to calculate the offset and the DST.
        <script> var now = new Date();
                    var jan1st=new Date(now.getFullYear(), 0, 1, 0, 0, 0,
0);
                    var june1st = new Date(now.getFullYear(), 0, 1, 0, 0 ,0
0)
                    /*calculate the offset and dst */
         </script>
      You can google it.

I use Joda-time plugin to deal with datetime.


Slavoj Žižek wrote:
>
> Hi!
>
> I am creating an international web application where one can create an
> event
> in its own local timezone, but someone outside of this zone needs to see
> this date&time in it's local time zone. So basically I need to get this
> two
> questions answered:
>
> 1. How do I obtain users timezone ? (from request header ??)
> 2. How do I convert time and date from one time zone to another using
> groovy?
>
>
> Thanks for answers.
>
> Slavoj
>
>

--
View this message in context: http://old.nabble.com/How-to-convert-date-time-from-one-time-zone-to-another--tp26558434p26558892.html
Sent from the grails - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to convert date&time from one time zone to another?

HubertChang
In reply to this post by Slavoj Žižek
http://grails.org/plugin/joda-time
http://joda-time.sourceforge.net/userguide.html

Some more information for Javascript Timezone detection.
    http://carters-site.net/wordpress/2009/04/javascript-figuring-out-daylight-savings-time/comment-page-1/
   
   var now = new Date();
   var tz = now.getTimezoneOffset();

Slavoj Žižek wrote
Jeff, I am only displaying dates. So I have to store dates in database in
one format but display in others. Found a pure java solution here
http://snipplr.com/view/104/convert-from-one-timezone-to-another/ , but
don't know how should the string parameters be formatted.

Hubert, I didn't find the page about joda-time very helpful, any examples to
clear thing up ?




On Sun, Nov 29, 2009 at 3:32 AM, Hubert Chang <huixiu@gmail.com> wrote:

>
> Request header doesn't have the information for timezone.
> Two ways to detect the client timezone, one is
>    1, with GeoIP database to decide the client's timezone
>    2, with a javascript to calculate the offset and the DST.
>         <script> var now = new Date(); > var jan1st=new Date(now.getFullYear(), 0, 1, 0, 0, 0, > 0); > var june1st = new Date(now.getFullYear(), 0, 1, 0, 0 ,0 > 0) > /*calculate the offset and dst */ > </script>>       You can google it.
>
> I use Joda-time plugin to deal with datetime.
>
>
> Slavoj Žižek wrote:
> >
> > Hi!
> >
> > I am creating an international web application where one can create an
> > event
> > in its own local timezone, but someone outside of this zone needs to see
> > this date&time in it's local time zone. So basically I need to get this
> > two
> > questions answered:
> >
> > 1. How do I obtain users timezone ? (from request header ??)
> > 2. How do I convert time and date from one time zone to another using
> > groovy?
> >
> >
> > Thanks for answers.
> >
> > Slavoj
> >
> >
>
> --
> View this message in context:
> http://old.nabble.com/How-to-convert-date-time-from-one-time-zone-to-another--tp26558434p26558892.html
> Sent from the grails - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>
http://grails.org/plugin/joda-time
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to convert date&time from one time zone to another?

basejump (Josh)
You may also want to check this out
http://timeago.yarp.com/


On Nov 28, 2009, at 9:37 PM, Hubert Chang wrote:

>
> http://grails.org/plugin/joda-time
> http://joda-time.sourceforge.net/userguide.html
>
> Some more information for Javascript Timezone detection.
>
> http://carters-site.net/wordpress/2009/04/javascript-figuring-out-daylight-savings-time/comment-page-1/
>
>   var now = new Date();
>   var tz = now.getTimezoneOffset();
>
>
> Slavoj Žižek wrote:
>>
>> Jeff, I am only displaying dates. So I have to store dates in database in
>> one format but display in others. Found a pure java solution here
>> http://snipplr.com/view/104/convert-from-one-timezone-to-another/ , but
>> don't know how should the string parameters be formatted.
>>
>> Hubert, I didn't find the page about joda-time very helpful, any examples
>> to
>> clear thing up ?
>>
>>
>>
>>
>> On Sun, Nov 29, 2009 at 3:32 AM, Hubert Chang <[hidden email]> wrote:
>>
>>>
>>> Request header doesn't have the information for timezone.
>>> Two ways to detect the client timezone, one is
>>>   1, with GeoIP database to decide the client's timezone
>>>   2, with a javascript to calculate the offset and the DST.
>>>        <script> var now = new Date();
>>>                    var jan1st=new Date(now.getFullYear(), 0, 1, 0, 0, 0,
>>> 0);
>>>                    var june1st = new Date(now.getFullYear(), 0, 1, 0, 0
>>> ,0
>>> 0)
>>>                    /*calculate the offset and dst */
>>>         </script>
>>>      You can google it.
>>>
>>> I use Joda-time plugin to deal with datetime.
>>>
>>>
>>> Slavoj Žižek wrote:
>>>>
>>>> Hi!
>>>>
>>>> I am creating an international web application where one can create an
>>>> event
>>>> in its own local timezone, but someone outside of this zone needs to
>>> see
>>>> this date&time in it's local time zone. So basically I need to get this
>>>> two
>>>> questions answered:
>>>>
>>>> 1. How do I obtain users timezone ? (from request header ??)
>>>> 2. How do I convert time and date from one time zone to another using
>>>> groovy?
>>>>
>>>>
>>>> Thanks for answers.
>>>>
>>>> Slavoj
>>>>
>>>>
>>>
>>> --
>>> View this message in context:
>>> http://old.nabble.com/How-to-convert-date-time-from-one-time-zone-to-another--tp26558434p26558892.html
>>> Sent from the grails - user mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe from this list, please visit:
>>>
>>>   http://xircles.codehaus.org/manage_email
>>>
>>>
>>>
>>
>>
> http://grails.org/plugin/joda-time http://grails.org/plugin/joda-time 
> --
> View this message in context: http://old.nabble.com/How-to-convert-date-time-from-one-time-zone-to-another--tp26558434p26559122.html
> Sent from the grails - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: How to convert date&time from one time zone to another?

aggiepilot04
In reply to this post by Slavoj Žižek
Old question, but there still wasn't an easy way to do this (that I know of).  I recently built a plugin that makes it a bit easier though.

https://grails.org/plugin/timezone-detection

The dates/times collected from the user are adjusted to server time.  This is much easier if you leave your server on UTC (and you should).

Dustin
Loading...