Skip to content
Loading
 
 
Here i use Jquery and Moment js cdn links . In format function you can give your desire format.
you can learn more about moment js in their official website : https://momentjs.com 
+4
  • Priyanka Jain
    +3
    You can check below link it uses date.format.js having format function which can format your date in which you want
     
    http://embed.plnkr.co/P05l1a/preview 
    +3
  • +3
    Hello 
     
    Following code may help you:
     
    1.   
      function dateFormate(orginaldate) {
      var date = new Date(orginaldate);
      var day = date.getDate();
      var month = date.getMonth() + 1;
      var year = date.getFullYear();
      if (day < 10) {
      day = "0" + day;
      }
      if (month < 10) {
      month = "0" + month;
      }
      var date = month + "/" + day + "/" + year;
      return date;
      };
    +3
  • +2
    The JSON specification does not specify a format for exchanging dates which is why there are so many different ways to do it. The problem with dates in JSON and JavaScript in general – is that there's no equivalent literal representation for dates. In JavaScript/jQuery following Date constructor straight away converts the milliseconds since 1970 to Date as follows:
    var jsonDate = new Date(1297246301973);
    Then let's convert it to js format:
    var date = new Date(parseInt(jsonDate.substr(6)));
    The substr() function takes out the /Date( part, and the parseInt() function gets the integer and ignores the )/ at the end. The resulting number is passed into the Date constructor .
    For ISO-8601 formatted JSON dates, just pass the string into the Date constructor:
    var date = new Date(jsonDate);
     
    http://net-informations.com/jq/iq/jdate.htm
    +2
  • Ankit Kanojia
    +2
    Hi Reylin Mathew,
     
    Please try below single line code, it will work for you as per your requested format for date.
    1. new Date("8/9/2019").toLocaleDateString('en-US', {year: 'numeric', month: '2-digit', day: '2-digit'}); 
     This will return the date value with format like "08/09/2019"
    +2
  • Vishal  Patel
    +1
    You can check below link to use moment js is best for any type of date conversion 
     
    please follow this url and generate output based on your requirment. 
     
    http://jsfiddle.net/JamesWClark/9PAFg/ 
    +1
  • Bidyasagar Mishra
    +1
    follow the below link 
    https://stackoverflow.com/questions/23946698/changing-date-time-format-using-jquery-javascript 
    +1