get timezone abbreviation javascript code example
Example 1: javascript convert timezone name to abbreviation
// Doing this:
<script src="moment.js"></script>
<script src="moment-timezone.js"></script>
<script src="moment-timezone-data.js"></script>
<script>
moment().tz("America/Los_Angeles").zoneAbbr();
</script>
// Returns:
'PDT' // Timezone's abbreviation
Example 2: javascript date timezone
// this example takes 2 seconds to run
const start = Date.now();
console.log('starting timer...');
// expected output: starting timer...
setTimeout(() => {
const millis = Date.now() - start;
console.log(`seconds elapsed = ${Math.floor(millis/1000)}`);
// expected output : seconds elapsed = 2
}, 2000);