javascript - How to parse date field from json using angularJs filter -


here i'm getting json file /date(1435837792000+0000)/

i need display date in following format oct 29, 2010 9:10:23 am

there no function format() on date prototype in javascript. there these methods:

getdate() // returns date getmonth() // returns month getfullyear() // returns year gethours() // returns hour getminutes() // returns minute getseconds() // returns second 

you can form string using:

function formatdate(dt) {     var monthnames = ["january", "february", "march", "april",         "may", "june", "july", "august", "september",         "october", "november", "december"];      var h = dt.gethours(), am;     if (h > 12) {         = 'pm';         h = h - 12;     } else {         = 'am';     }      return monthnames[dt.getmonth()].substring(0, 3) + ' ' +         dt.getdate() + ', ' + dt.getfullyear() + ' ' +         h + ':' + dt.getminutes() + ':' + dt.getseconds() + ' ' +         am; }  console.log(formatdate(new date(1435837792000+0000))); 

if finding yourselves in need of more date parsing , formatting, check out momentjs library. moment, do:

moment(new date(1435837792000+0000)).format("mmm d, yyyy hh:mm:ss a") 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -