Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Get Iphone Deveice Timezone

I want the value of Iphone Device Timezone set by any user in his/her Iphone using Titanium???
So if anyone finds solutions please do post me ASAP…it will be a great help to me…
Waiting for positive response from someone…

— asked May 18th 2010 by Sandil Shah
  • iphone
  • mobile
1 Comment
  • I know what you mean. Urban Airship's push notification quiet times requires the system's timezone, which is something like: America/LosAngeles

    — commented July 29th 2011 by Caio Iglesias

4 Answers

  • Is there any reason standard javascript can't be used for this? I don't see that titanium needs to provide anything at all. For example:

    var dt = new Date();
    var offset = dt.getTimezoneOffset();
    var tz = dt.toString();        // ends with (time zone name)
    tz = tz.replace(/^.*\(/,"");   // Remove leading text through (
    tz = tz.replace(/\).*$/,"");   // Remove trailing text from )
    Ti.API.info(tz + ' is ' + offset + ' minutes from UTC');
    — answered February 7th 2011 by Doug Handy
  • +1, would like to know if this is possible. I'm pulling down UTC date/time and computing time difference in days/hours. Thanks.

    — answered February 6th 2011 by Ryan Gartin
  • I agree with Doug's post, use all JS to get the offset.

    What are you planning on doing with it?

    If just displaying the name, as suggested parse it out.

    If performing a calculation take the value of date.getTimezoneOffset() which is in minutes and multiply into millseconds (60s * 1000ms) before using it.

    — answered February 7th 2011 by Nick The Geek
  • To Ryan's question, you can create a Date object and use the Date.setUTC{*} functions to create your UTC time then you can get the local time from the Date object.

    — answered February 7th 2011 by Nick The Geek
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.