0
new Date().toLocaleString() --> "‎24‎/‎09‎/‎2015‎ ‎10‎:‎14‎:‎00‎ ‎PM"
new Date("2015-09-24 09:38:32.639").toLocaleString() --> "Invalid Date"

How can I format a date object from a timestamp in string format?

SOLUTION: At the end I got it fixed changing my date type in the server from DateTime to Instant, js will atomatically add zone offset automatically from a timestamp and will format the dates in the right way.

NOTE: I know this question is duplicated, however the solution proposed is different and may help other users to get a different approach to their code.

masber
  • 2,875
  • 7
  • 29
  • 49

1 Answers1

1
var myDate = "2015-09-24 09:38:32.639";

new Date(myDate.replace(/-/g,"/")).toLocaleString()

Now it's working fine

Man Programmer
  • 5,300
  • 2
  • 21
  • 21