javascript - How to setMonth using month names, and displaying a specific day and year -
question: how can use new date();
object display full month name, day of month, , year time stamp?
function displaylastmod() { montharray = new array(11); montharray[0] = "january"; montharray[1] = "february"; montharray[2] = "march"; montharray[3] = "april"; montharray[4] = "may"; montharray[5] = "june"; montharray[6] = "july"; montharray[7] = "august"; montharray[8] = "september"; montharray[9] = "october"; montharray[10] = "november"; montharray[11] = "december"; var thedate = new date(); var themonth = thedate.setmonth(03); var theday = thedate.setdate(09); var theyear = thedate.setyear(2015); document.getelementbyid("lastmodified").innerhtml = "last modified: " +thedate; }
this code displays "last modified: thu apr 09 2015 18:18:37 gmt-0500 (central daylight time)"
this format need in: "last modified: april 9, 2015 - 6:23:00 pm"
is possible using javascript (without other languages or plugins)?
as know there no function in javascript print formated date.
try this:
function displaylastmod() { montharray = new array(11); montharray[0] = "january"; montharray[1] = "february"; montharray[2] = "march"; montharray[3] = "april"; montharray[4] = "may"; montharray[5] = "june"; montharray[6] = "july"; montharray[7] = "august"; montharray[8] = "september"; montharray[9] = "october"; montharray[10] = "november"; montharray[11] = "december"; thedate = new date();thedate.sethours(16); var themonth = thedate.setmonth(03); var theday = thedate.setdate(09); var theyear = thedate.setyear(2015); var monthname=montharray[thedate.getmonth()] var day=thedate.getdate(); var year=thedate.getyear()+1900; var hours=thedate.gethours() var minutes=thedate.getminutes(); var seconds=thedate.getseconds(); document.getelementbyid("lastmodified").innerhtml = ("last modified: " +monthname+' '+day+', '+year+' - '+hours%12+':'+minutes+':'+seconds+' '+((hours>12)?'pm':'am')); }