Sunday, 21 June 2015

how to show time picker dialog in titanium?

show time picker dialog is very simple in titanium. Titanium use javascript code to get time we can change based on our requirement

imagetime.addEventListener('click',function(e)
{
pickerRecallTime = Ti.UI.createPicker({
   //top: 70,
   //left: 10,
   useSpinner: true,
   format24: false,
   selectionIndicator: true,
   type: Ti.UI.PICKER_TYPE_TIME
});

       pickerRecallTime.showTimePickerDialog({
           callback: function(e) {
               if (e.cancel) {
                   Ti.API.info('user canceled dialog');
       } else {
           //Ti.API.info('user selected Time: ' + e.value);
           //starttimefield.setValue(e.value);          
            var data = e.value;
    var hours = data.getHours();
    var minutes = data.getMinutes();    

starttimeflag=hours+':'+minutes;

 var ampm = hours >= 12 ? 'PM' : 'AM';
 hours = hours % 12;
 hours = hours ? hours : 12; // the hour '0' should be '12'
 minutes = minutes < 10 ? '0'+minutes : minutes;
 var strTime = hours + ':' + minutes + ' ' + ampm;
 //return strTime;  
    timefield.setValue(strTime);// set time in time field
   
       }
   }
});
});