Search code examples
iosdatetimetitaniumtitanium-mobile

Get device time/local time from UTC time in Titanium


I'm working on an Titanium application. In which I want to take the local time. My issue is, when I use:

var currentDateTime = new Date();

It shows the UTC time.

Is there anyway to get the current local time or device time ?


Solution

  • I fixed the issue using the getTimezoneOffset function.

    I wrote a method which takes the UTC time as parameter and returns the local time

    //Function Processes the passed UTC time and returns the current device time.
    function changeUTCToLocal(utcTime)
    {
        var offset = utcTime.getTimezoneOffset();
        var localTime = utcTime + offset;
        return localTime;
    }