I have string as 06/08/2013
that I want to convert into Date Object
I do
var transactionDate = Date.parse(transactionDateAsString);
and I get NaN
How can I tell javascript to format the string as dd/mm/yyyy
?
I have string as 06/08/2013
that I want to convert into Date Object
I do
var transactionDate = Date.parse(transactionDateAsString);
and I get NaN
How can I tell javascript to format the string as dd/mm/yyyy
?
Break it down and spoon-feed it:
var parts = transactionDateAsString.split("/");
var date = new Date(parts[2],parts[1]-1,parts[0]);
Date.parse()
from the docs:
Parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC.
You probably want to use the Date
constructor:
var transactionDate = new Date(transactionDateAsString);