11 Replies Latest reply: Feb 28, 2011 3:26 PM by Manjit RSS

    Internationalization  issue : convert date/time to GMT/UTC

    Manjit
      We have our webservices running in websphere /oracle.There is this requirement to internationalize the application ...like
      a) language .....
      .
      .

      d)Internatiolization of time :
      For this requirment I am planning to do the following.Service request with date will be converted to GMT before it is stored in database and the response back will be converted from GMT back to the time zone of the requester and have the application server/database server configured to UTC time.Is this a good strategy or is there a better one.

      Thanks
      m
        • 1. Re: Internationalization  issue : convert date/time to GMT/UTC
          sabre150
          Manjit wrote:
          For this requirment I am planning to do the following.Service request with date will be converted to GMT before it is stored in database and the response back will be converted from GMT back to the time zone of the requester and have the application server/database server configured to UTC time.Is this a good strategy or is there a better one.
          This is the strategy employed by Java's java.util.Date, java.sql.Date and java.ql.Timestamp ; they all store the number of milliseconds since 1/1/1970 00:00:00:000 UTC. If you use any of these with PreparedStatments then you will have nothing to do. Do not even think about storing the data as a varchar since this would mean you would have to do all the hard work yourself.
          • 2. Re: Internationalization  issue : convert date/time to GMT/UTC
            836548
            Save the time in TimeStamp i.e in milli seconds, and when displaying use the localmachine timezone.
            • 3. Re: Internationalization  issue : convert date/time to GMT/UTC
              Manjit
              I am little lost .

              Sorry I was wrong about one thing.We are not configuring our server to have UTC time but it will have the zonal time.

              Did you say that new Date() returns UTC time .I believe it returns the time of current zone.'


              Are you suggesting that I dont convert incoming request .Meaning if a request A comes from say Egypt at 10 pm and the server is running in NewYork then it will save the request in newyork time 10 am (egypt is 10 hour ahead of new york) because new Date() will give the new york time.

              Now some one in egypt wanted to see a report of all the request made between 10 pm and 11 pm.This service request will not get A becuase in database it was stored at 10 am.

              If A was stored in UTC time ,if the reporting request was converted to UTC then it would have returned record A back

              Please let me know if I missed anything.
              • 4. Re: Internationalization  issue : convert date/time to GMT/UTC
                Manjit
                Okay I got the new Date() puzle.When you say date return UTC time..it means it does return the zone.Just did print of new Date and I do get the zone.Atleast this riddle is solved.
                Fri Feb 25 11:21:18 EST 2011



                But still not sure about the other riddle.Remember in my oracle databse we have the date field as Date and not Timestamp.I still feel we should convert to/fro dates to GMT.
                • 5. Re: Internationalization  issue : convert date/time to GMT/UTC
                  sabre150
                  Manjit wrote:
                  But still not sure about the other riddle.Remember in my oracle databse we have the date field as Date and not Timestamp.I still feel we should convert to/fro dates to GMT.
                  The Oracle Date field can be set using a PreparedStatement and using java.sql.TimeStamp objects. Effectively java.sql.TimeStamp objects already store the date as UTC which can be regarded as GMT. No conversion required. Don't make work for yourself.
                  • 6. Re: Internationalization  issue : convert date/time to GMT/UTC
                    Manjit
                    But we use jpa/hibernate and not prepared statement
                    • 7. Re: Internationalization  issue : convert date/time to GMT/UTC
                      sabre150
                      Manjit wrote:
                      But we use jpa/hibernate and not prepared statement
                      Then you will need to make the appropriate mappings in the Hibernate configuration files! I know little about Hibernate but I know this can be done!
                      • 8. Re: Internationalization  issue : convert date/time to GMT/UTC
                        Manjit
                        thank you Sabre and 833545 for your help.You guys saved me time !

                        thx
                        m
                        • 9. Re: Internationalization  issue : convert date/time to GMT/UTC
                          Manjit
                          Sabre,to confirm again...you are suggesting that there is even no need to change the oracle Date field from Date type to Timestamp.The only thing I really have to do is for display purpose convert/format the response date to the zone the request is coming from.Please let me know if I missed anything.




                          thx
                          m
                          • 10. Re: Internationalization  issue : convert date/time to GMT/UTC
                            jschellSomeoneStoleMyAlias
                            Manjit wrote:
                            Sabre,to confirm again...you are suggesting that there is even no need to change the oracle Date field from Date type to Timestamp.The only thing I really have to do is for display purpose convert/format the response date to the zone the request is coming from.Please let me know if I missed anything.
                            The above statement is indefinite.

                            Are you starting with a java.util.Date or perhaps a java.sql.Timestamp?

                            Then you do NOT convert them. You display them. You use SimpleDateFormat for that. You do not concern yourself at all with timezones exception in terms of creating a SimpleDateFormat. And that is ONLY an issue if you are creating the string (display value) on a server. If you are doing that you will need the client to provide you with a timezone. There is no magic way to get that from the client. If a client app is doing the display the the client is running in a client VM and that VM will already have a display format that might be suitable.

                            Conversely if you are receiving a timestamp value as a text value (say read it from a file) then you must convert that into a java.util.Date. You do that via SimpleDateFormat. The specifics of how you do that depends on the form of the text value.
                            • 11. Re: Internationalization  issue : convert date/time to GMT/UTC
                              Manjit
                              Thank you Schell and all you guys who responded to my query.I am perfectly clear now.

                              Thanks again