-1

I am using angular JS, my Server returning a date like below. When I tried to convert it to Date format it is saying "Invalid Date". Please any suggestions? Below is the sample of server date.

function runSettlement() {
    return Restangular.one('/api/GetdateofLastrun').get().then(function 
(data) {
 var serverDate = new Date(data);
Console.log(data); //Invalid Date
}

Here the API call returns below data from server. 21-04-2017 20:34:30 UTC +05:30

Vishnu
  • 21
  • 2
  • 5
  • 2
    Ideally, the API on the server should emit that timestamp in standard ISO8601 format, which would be `"2017-04-21T20:34:30+05:30"`. – Matt Johnson-Pint Apr 21 '17 at 16:30
  • The error "Invalid date" means that it's an invalid date. Look up the `Date` function to see what dates are valid. `Date` cannot read your mind and convert any arbitrary date format in the world. It converts dates in a particular, predefined format. –  Apr 21 '17 at 16:33

1 Answers1

-1

JavaScript Date Objects don't support that format.

I would recommend https://momentjs.com/

"Parse, validate, manipulate, and display dates and times in JavaScript."

Angular directives for Moment.js can be found at: https://github.com/urish/angular-moment

MattSizzle
  • 3,145
  • 1
  • 22
  • 42
  • I don't see why this answer was down voted. Especially considering it provided the documentation that the comments did not. – MattSizzle Apr 21 '17 at 16:50
  • Not my down vote, but likely it's seen as just a recommendation to use a library that isn't tagged or mentioned in the OP. Down votes without comments are useless. – RobG Apr 22 '17 at 00:07