Format UTC dates to a specific timezone

Abstract

How to format UTC dates to specific timezones when building a real-time audience (Sitecore Personalize).

There is often a need to convert UTC dates to a specific timezone when you build a real-time audience. For example, you might want to display the date and time of an event for a specific timezone. To do this, you can use the moment-timezone.js library, which converts the UTC date to a specific timezone, also taking into account daylight savings.

To use the moment-timezone.js library, include the following code snippet in your JavaScript:

load("classpath:moment.js");
load("classpath:moment-timezone.js");

Important

You must load the moment.js library first, as shown in the example.