javascript - get month,date and year from given date -


this question has answer here:

i want month , date given date.i server time . date="wed jul 26 2017 11:39:44 gmt+0530 (india standard time)"; want mm/dd/yyyy given date

        var xmlhttp;     function srvtime(){     try {         //ff, opera, safari, chrome         xmlhttp = new xmlhttprequest();     }     catch (err1) {         //ie         try {             xmlhttp = new activexobject('msxml2.xmlhttp');         }         catch (err2) {             try {                 xmlhttp = new activexobject('microsoft.xmlhttp');             }             catch (eerr3) {                 //ajax not supported, use cpu time.                 alert("ajax not supported");             }         }     }     xmlhttp.open('head',window.location.href.tostring(),false);     xmlhttp.setrequestheader("content-type", "text/html");     xmlhttp.send('');     return xmlhttp.getresponseheader("date");     }     var st = srvtime();     var date = new date(st);       console.log(date); //wed jul 26 2017 11:39:44 gmt+0530 (india standard time) 

you can use getdate(), getmonth() , getfullyear(). add 1 month javascript return months 0 january, 1 february, etc.

var date = new date();    var day = date.getdate();  var month = date.getmonth() + 1;  var year = date.getfullyear();    console.log('day:' + day);  console.log('month:' + month);  console.log('year:' + year);    if(day < 10){      day='0'+day;  }   if(month<10){      month='0'+month;  }   var today = month+'/'+day+'/'+year;  console.log('date:' + today);


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -