0

My web method is sending a date string to JavaScript e.g. "05/06/2014 09:00:00" in "dd/MM/yyyy hh:mm" format. But When I try to create a Date object in javascript it inverts the day and month. How Can I have a date object in JavaScript with "dd/MM/yyyy hh:mm" format.

V.B
  • 1,191
  • 7
  • 29
  • 55

1 Answers1

0

You can use regular expression to make the changes.

var dateString= ... ; // "MM/dd/yyyy hh:mm"
dateString = dateString.replace( /(\d+)\/(\d+)\/(\d+)/i , "$2/$1/$3");
// dateString = "dd/MM/yyyy hh:mm"
GramThanos
  • 3,572
  • 1
  • 22
  • 34