javascript - Convert epoch time to date in titanium -


i have epoch times stored in database so: 1392821307. these picked on separate web service using php time() function. need convert date/month/year format in titanium.

so far have used following code based off answer here in stack overflow

var utcseconds = jobs_data.jobs[i].dateposted; var d = new date(0); // 0 there key, sets date epoch d.setutcseconds(utcseconds); 

this returns string so:

wed feb 19 14:48:27 gmt 2014 

i need feb 19 2014. i'm wondering how parse string. going use substring example, mon have 3 letters , thurs have 4, starting index of parse changing. not sure if month of varying length also

d date object. if pass ti.api.info, or console.log, it'll coerced in string see above. should use getdate, getmonth, , getfullyear methods string want.

var formattedstring = (d.getmonth()+1) + '/' + d.getdate() + '/' + d.getfullyear(); 

alternatively, use moment.js, included in alloy apps, , can downloaded in vanilla titanium apps too:

var moment = require('alloy/moment'),     dm = moment(d),     formattedstring = dm().format('l'); 

this answered quite answer already:

where can find documentation on formatting date in javascript?


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -