how to convert default date in javascript to YYYY-MM-DDTHH:MM:SS format.
new Date() returns Sun Aug 07 2016 16:38:34 GMT+0000 (UTC)
and i need the current date to above format.
As new Date().toISOString()
will return current UTC time, to get local time in ISO String format we have to get time from new Date()
function like the following method
document.write(new Date(new Date().toString().split('GMT')[0]+' UTC').toISOString().split('.')[0]);
You can use moment.js library to achieve this.
Try:
var moment = require('moment')
let dateNow = moment().format('YYYY-MM-DDTHH:MM:SS')
This could work :
var date = new Date();
console.log(date.getFullYear() + "-" + (date.getMonth()+1) + "-" + date.getDate() + " " + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds());
For use the date in ISO 8601 format run the command lines below on NodeJS console or on browser console:
$ node
> var today = new Date(); // or
> var today = new Date(2016, 8, 7, 14, 06, 30); // or
> var today = new Date('2016-08-07T14:06:30');
> today; // Show the date in standard USA format. Grrrr!
> today.toISOString();
For more information, consult the documentation: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With