javascript date from iso string code example

Example 1: get iso date javascript

var isoDate = new Date().toISOString()

Example 2: javascript date to string

// There are two flavours
const event = new Date(1993, 6, 28, 14, 39, 7);

// The Old Skool Flava
console.log(event.toString());
// expected output: Wed Jul 28 1993 14:39:07 GMT+0200 (CEST)
// (note: your timezone may vary)

// The Hipster way ;)
console.log(event.toDateString());
// expected output: Wed Jul 28 1993

Example 3: js string to date

var myDate = new Date("2013/1/16");

var str = "2013/1/16";
var strToDate = new Date(str);

Example 4: parse date from string in js

Date.parse(dateString)
//dateString is like 2020-10-10 / 2020-10-10T10:20:20

Example 5: how to get time and date from iso string javascript

const myDate = "2012-10-16T11:00:28.556094Z";
const time = new Date(myDate).toLocaleTimeString('en',
                 { timeStyle: 'short', hour12: false, timeZone: 'UTC' });

// Output:  "11:00"

Example 6: iso to date javascript

date = new Date('2013-03-10T02:00:00Z');
date.getFullYear()+'-' + (date.getMonth()+1) + '-'+date.getDate();//prints expected format.

Tags: