JSFiddle - React, Tailwind, and code Playground
by habla
JavaScript
// Util functions
function leftPad2(s) {
s = '' + s
return s && s.length == 1 ? '0' + s : s
}
const serverFormattedUtcString = "2020-02-18T22:38:00.000Z"
// Code to format this in local time
const offsetMinutesFromCookie = 660
const dateObject = new Date(serverFormattedUtcString)
// Apply offset, now UTC time within that Date is the date we want to display. The date
// is technically incorrect, but this will do the job.
dateObject.setUTCMinutes(dateObject.getUTCMinutes() + offsetMinutesFromCookie)
const formattedString = leftPad2(dateObject.getUTCDate()) + '/' + leftPad2(dateObject.getUTCMonth() + 1) + '/' + dateObject.getUTCFullYear() + ' ' + leftPad2(dateObject.getUTCHours()) + ':' + leftPad2(dateObject.getUTCMinutes())
alert(formattedString)