moment-browser.js is an extension to moment.js that helps convert Dates to/from the Browser Timezone to the TimeZone required by your browser based applications. E.g. You have a datepicker which the user expects to be in New York TZ, but you are using the application in the Pacific Timezones. When you display your server provided UTC Date Times they will show in the Browser TZ. This moment extension will create a new Date which helps offset the difference between the browser TZ and the TZ required by the application.
Works with browser environments.
<!-- Browser -->
Creates a converter helper object which handles conversion to and from the Browser TZ.
var newYorkDate = momentBrowser.tz("2017-02-02 12:00", "America/New_York"); var converter = newYorkDate.browserConverter();
Creates a new date object which is a datetime modified to replicate the display timezone. browserTimeZone is optional the code will try and guess it.
var newYorkDateInBrowser = converter.asDisplayTz('America/New_York'); var newYorkDateInBrowser = converter.asDisplayTz('America/New_York', 'America/Los_Angeles');
Now a user makes a selection in the UI and changes the DateTime. On the workflow back to the server we need to convert this date back to it's correct current browser TimeZone value.
var onePmPST = momentBrowser.tz("2017-02-02 13:00", "America/Los_Angeles"); var newYorkDateOnePm = converter.fromDisplayTz(onePmPST)