简体   繁体   中英

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,

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM