Titanium Time Helpers

For a recent project of mine I have to present different picker controls to the user based on their device time settings.  Unfortunately I couldn’t leverage the standard picker control since I need to present the user with only the hour picker instead of the full time picker.

Below is a function that will return a bool indicating if the user’s device settings are configured to AM/PM or to display 24 hour time.

 

1 function deviceTimeIs24(){
2 //Get Time Formatted value and remove the separator
3 var temp = String.formatTime(new Date())
4 .replace(':','')
5 .replace(/^\s\s*/, '')
6 .replace(/\s\s*$/, '');
7
8 /*If not in 24 hour format the temp value
9 will not be a number for example 641PM.
10 If is in 24 hour format it will be all numbers */
11 return !isNaN(parseFloat(temp)) && isFinite(temp);
12 };

0 comments:

Post a Comment