The Light
The Light

Reputation: 27011

In JavaScript, How to Convert a date time value from one format to the other?

Please look at the format of these date time values:

var from = "2012-01-13 T11:00:00";
var to = "13 Jan 2012 11:00am";

In the above example, how to write a javascript function which converts a value in "from" format to a value in "to" format, both are datetime values in text obvioulsy.

var to = convertDateTime(from);
function convertDateTime(from)
{
// how to implement this?
}

Many thanks,

Upvotes: 0

Views: 1825

Answers (2)

kapa
kapa

Reputation: 78671

You can use a library like XDate that will handle this for you.

There is no need to reinvent the wheel. When working with dates, you can run into several browser inconsistencies.

Upvotes: 1

Jerome Cance
Jerome Cance

Reputation: 8183

look at this article : http://blog.stevenlevithan.com/archives/date-time-format

you must convert your string object into date type and then retransform it to string using date format

Upvotes: 2

Related Questions