function test (date){ let time = new Date(date).toLocaleString(), timeIos = new Date(date.replace(/-/g, '/')).replace('T', ' ').toLocaleString() if (time !== 'Invalid Date'){ return time } if (timeIos !== 'Invalid Date'){ return timeIos } return date } alert('2016-12-02T02:13:05.688Z')