简体   繁体   中英

How to convert a date in other format?

I've a date with this format:

Mon Oct 19 2015 00:00:00 GMT+0200 (ora legale Europa occidentale)

My goal is convert a date into this format:

2015-10-19T00:00:00

How I can achieve this result?

UPDATE

var currDateEnd = $('#calendar').fullCalendar('getView').start;
                        currDateEnd.toISOString();
                        console.log("currDateEnd iso => ", currDateEnd.toDate().toDateString());
moment().format();  // results in something like : 2015-10-25T13:09:29-04:00

You could just snip off the end part if you wanted. (The timezone part, -04:00)

Source: Moment.js

this Mon Oct 19 2015 00:00:00 GMT+0200 (ora legale Europa occidentale) is the String representation of Javascript Date Object , so use this function .toISOString(); like this

Demo

var d = new Date();
$(".yo").append("The String of the object -> "+d.toString()+"<br>");
$(".yo").append("What you want -> "+d.toISOString());

try this

var currDateEnd = $('#calendar').fullCalendar('getView').start;
console.log("currDateEnd iso => ", currDateEnd.toDate().toISOString());

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