Raja
Raja

Reputation: 219

convert string to Default date Format

Hi I have use the string object for represent the date in the following format

var date="18/01/2011";
var dateFormat="dd/MM/yyyy";

Note:

In my scenorio i have use the dd/MM/yyyy format;

dateFormat will be different in my client side.

how to convert these date default JavaScript dateFormat as MM/dd/yyyy in Generic way.

I have tried in by split date by and swap the month ,date to achieve this requirement. But in my client side i dont know about the format of the date how to convert any other format to default Javascript format

Upvotes: -2

Views: 738

Answers (2)

ReeCube
ReeCube

Reputation: 2587

Hope this helps:

var date="18/01/2011";
var parts = date.split('/');
var result = new Date(parts[2], parts[1], parts[0]);

Upvotes: 0

Alok Nath
Alok Nath

Reputation: 141

var datestring = "2014-02-27:04:05";var d = Date(datestring);

Upvotes: -1

Related Questions