How to ISO 8601 format a Date with Timezone Offset in JavaScript?

Here’s a simple helper function that will format JS dates for you. function toIsoString(date) { var tzo = -date.getTimezoneOffset(), dif = tzo >= 0 ? ‘+’ : ‘-‘, pad = function(num) { return (num < 10 ? ‘0’ : ”) + num; }; return date.getFullYear() + ‘-‘ + pad(date.getMonth() + 1) + ‘-‘ + pad(date.getDate()) … Read more