subchap
subchap

Reputation: 847

Time format in Phonegap

In phonegap, is it possible to show the time in am/pm or 24-hour format according to the device settings in iOS? On the device, I can set the "24-Hour Time" to be on or off in settings. In the phonegap app, I want to adjust the time format according to the settings.

Thanks.

Upvotes: 1

Views: 432

Answers (2)

Omar Meky
Omar Meky

Reputation: 606

You can just cordova's built in globalization plugin. If you run for example,

navigator.globalization.dateToString(
    new Date(),
    function (date) { alert('date: ' + date.value + '\n'); },
    function () { alert('Error getting dateString\n'); },
    { formatLength: 'short', selector: 'date and time' }
);

date.value will hold a dateString that will reveal the time format (just check if "AM" or "PM" is in the string).

Upvotes: 0

Anil
Anil

Reputation: 2554

I checked the phoneGap documentation and there doesn't appear to be a way to know what the device time format settings are. But it's a good idea, you should submit a feature request to the Cordova (aka Phonegap) team for this feature.

http://docs.phonegap.com/en/2.0.0/cordova_device_device.md.html#Device

Now this isn't to say that a third party library doesn't exist that can work along side PhoneGap. But you would have to hunt for a plugin that does that or write your own. I did a quick Google search for this and nothing turned up for me.

Upvotes: 1

Related Questions