I'm working with the date and time in my Titanium based iOS application.
My issue is, I'm getting the time in the below format:
Wed Jan 16 2013 17:32:40 GMT+0530 (IST)
I want to change it like:
Jan 16, 2013, 05:32 pm
In iOS there is NSDateFormatter for doing this.
What I did :
split
and switch cases
, but it fails if the input time format changes, then I need to re-write the code for the changed format.Is there is anyway to do this in Titanium?
Please help, Thanks in advance.
I didn't find any alternatives for the NSDateFormatter
in Titanium.
I tested the Moment.js, but it didn't worked for my case.
I implemented a JavaScript function for achieving my output.
/**
* Function for formatting the date and time
* @param {Object} dateTime
*/
function formatDateTime(dateTime)
{
var arr = dateTime.split(' ');
var convertedDate = arr[1]+' '+arr[2]+', '+arr[3];
var convertedTime = arr[4];
var returnValue = convertedDate+', '+convertedTime;
return returnValue;
}
Edit on 27 Feb 2014
After facing the JavaScript date formatting issue on different occasions, I finally developed my own JavaScript module, this module will format the JavaScript Date object to Specified formats. You can find it here : MMP_DateTime