[Vuejs]-Display "hours and minutes" works on all browsers except safari. JavaScript Date

3πŸ‘

yes, this will not work on safari, as for ECMAScript 5 ISO-8601 format support:

Alternatively, the date/time string may be in ISO 8601 format. For
example, β€œ2011-10-10” (just date) or β€œ2011-10-10T14:48:00” (date and
time) can be passed and parsed.

you need to include T withing the date time in order to make it work on Safari:

new Date('2014-02-18T15:00:48');

you can try and do it like this:

new Date(dateFromLoop.replace(/\s/, 'T');
πŸ‘€Barr J

1πŸ‘

For a clean solution
There is a library called moment by using that you can do all your time and date manipulation

for your problem in Moment

const d = new Date(yourDate);
const hourAndMin = moment().format('h:mm'); 

Refer Moment

πŸ‘€Ananth

0πŸ‘

You can use Vanilla for this.

docs for parse

docs for format

The example direct from the source

var date = Date.parse('2018-08-06 20:45:00'.replace(' ', 'T'));

// toLocaleString without arguments depends on the implementation,
// the default locale, and the default time zone
console.log(new Intl.DateTimeFormat({
  hour: 'numeric',
  minute: 'numeric'
}).format(date));

Leave a comment