-1

im sending datetime from controller to a jquery function. I want to display this ("13.06.2021") format but i have "2020-11-29T00:00:00" like this

how can i convert it ?

function forexample()
{
  $.ajax({
  .......
   succes : function(data) {
       alert(data[i].mydate); //i want "13.06.2021" format
  }
})
}
  • Please visit [help], take [tour] to see what and [ask]. But first ***>>>[Do some research, search for related topics on SO](https://www.google.com/search?q=javascript+format+date+site:stackoverflow.com)<<<***; if you get stuck, post a [mcve] of your attempt, noting input and expected output, preferably in a [Stacksnippet](https://blog.stackoverflow.com/2014/09/introducing-runnable-javascript-css-and-html-code-snippets/) – mplungjan Jun 13 '21 at 05:47

1 Answers1

-1

You can get a JavaScript date object via:

d = new Date("2020-11-29T00:00:00")

Then get your desired format by getting the individual date components and creating a string from them.

// Month (0 is January)
d.getMonth() + 1

// Day
d.getDate()

// Year
d.getFullYear()
j3st
  • 345
  • 1
  • 8