JSFiddle - React, Tailwind, and code Playground

by hfougere

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.2/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.21/moment-timezone.min.js"></script>

JavaScript

var abbrs = {
    EST : 'Eastern Standard Time',
    EDT : 'Eastern Daylight Time',
    CST : 'Central Standard Time',
    CDT : 'Central Daylight Time',
    MST : 'Mountain Standard Time',
    MDT : 'Mountain Daylight Time',
    PST : 'Pacific Standard Time',
    PDT : 'Pacific Daylight Time',
};

let isVirtual = false;

let timeZoneName = isVirtual ? Intl.DateTimeFormat().resolvedOptions().timeZone : "America/Chicago";


	var m = moment.tz("2018-08-22T09:00:00", "America/New_York");
console.log(m.format());                    
m.tz("America/Chicago"); 
console.log(m.format()); 





   /*  let theDate = moment.tz("2018-02-22T09:00:00", timeZoneName);
    let abbr = theDate.format('z'); //tz name like EST or offest (if name not found)
    console.log(abbr);
    let offset = theDate.format('Z').split(':')[0];  // -05:00 -> -05
    let tzFullName = abbrs[abbr] || abbr;
    
    if (!isNaN(tzFullName)) {
        tzFullName = theDate.toDate().toString().match(/\(([A-Za-z\s].*)\)/)[1];
    }
    
    console.log(`${tzFullName} (UTC ${parseInt(offset)})`); */