# Support for different timezone

**URL:** <https://community.grafana.com/t/support-for-different-timezone/99526>\
**Category:** OSS Support\
**Created:** [August 23, 2022, 11:05pm UTC](https://community.grafana.com/t/support-for-different-timezone/99526 "2022-08-23T23:05:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ushanib](https://avatars.discourse-cdn.com/v4/letter/u/cc9497/32.png) [@ushanib](https://community.grafana.com/u/ushanib)\
**Post date:** [August 23, 2022, 11:05pm UTC](https://community.grafana.com/t/support-for-different-timezone/99526/1 "2022-08-23T23:05:26Z")

</div>

Hi Im trying to get the current date and time in London. I have used this method. But it just prints my current timezone.  
can you please help me with this?  
Thanks

```auto
   const date = new Date();

    console.log(
        date.toLocaleString('en-GB', {
            timeZone: 'Europe/London',
        }),
    );

```

---

<div class="post-metadata">

**Author:** ![oleiade](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/oleiade/32/35836_2.png) [@oleiade](https://community.grafana.com/u/oleiade)\
**Post date:** [August 29, 2022, 9:49am UTC](https://community.grafana.com/t/support-for-different-timezone/99526/3 "2022-08-29T09:49:19Z")

</div>

Hi @ushanib,

I believe there is no standardized way to do this in ES6 JS. However, I think you can approach this in two different ways.

Either, you could bundle your k6 project with the [moment js](https://momentjs.com/) library as described in our [step by-step instructions](https://k6.io/docs/using-k6/modules/). This solution could work, but you might encounter compatibility issues in the process, as k6’s JS interpreter is not 100% compliant with ES6 and might not support all the features’ moment depends on.

Or, you could write a tiny function that does the timezone offsetting manually. I believe there is no standard way of doing this in ES6, indeed (feel free to point me to resources showing otherwise if relevant 🙇‍♂️):

```auto
function shiftDateTZ(date, utcOffset) {
  // Number of milliseconds since the ECMAscript epoch
  const localTime = date.getTime();

  // Difference between local time and UTC time in milliseconds
  const localOffset = date.getTimezoneOffset() * 60000;

  // UTC time in milliseconds
  const utc = localTime + localOffset;

  // Compute the time for the selected offset to UTC in milliseconds
  const newDateTime = utc + 3600000 * utcOffset;

  // Return a new Date object with the offseted time
  return new Date(newDateTime).toLocaleString();
}

export default function () {
  // Get the current date and time
  const date = new Date();

  // Let's look for the time at UTC-4 (New York)
  const offset = -4;

  // Shift the date to the selected time zone
  const newDate = shiftDateTZ(date, offset);

  // Display the date and time
  console.log(`time in New York: ${newDate}`);
}

```

You pass the function the date object you want to offset from and the timezone difference relative to UTC you wish, and it will return a new `Date` object matching the timezone you’re looking for. This function is not as user-friendly as what you’d find in momentJS as it requires you to manually pass the offset to UTC of the timezone you would like to convert the `Date` to, but it should be reliable.

Please let me know if that was helpful and if you need any more support 🙇‍♂️

---

<div class="post-metadata">

**Author:** ![ushanib](https://avatars.discourse-cdn.com/v4/letter/u/cc9497/32.png) [@ushanib](https://community.grafana.com/u/ushanib)\
**Post date:** [September 5, 2022, 5:16am UTC](https://community.grafana.com/t/support-for-different-timezone/99526/4 "2022-09-05T05:16:23Z")

</div>

Any suggestion how to overcome when daylight saving occurs? Because offset will not always be the same. Im comparing the time with London and Melbourne time

---

<div class="post-metadata">

**Author:** ![oleiade](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/oleiade/32/35836_2.png) [@oleiade](https://community.grafana.com/u/oleiade)\
**Post date:** [September 5, 2022, 8:08am UTC](https://community.grafana.com/t/support-for-different-timezone/99526/5 "2022-09-05T08:08:36Z")

</div>

Hi @ushanib

Good question! I’ve found this [interesting SO thread](https://stackoverflow.com/questions/11887934/how-to-check-if-dst-daylight-saving-time-is-in-effect-and-if-so-the-offset) demonstrating how to find out if one is in DST time or not. Maybe it’s worth giving it a try. Let me know how it goes 🙇‍♂️

---

<div class="post-metadata">

**Author:** ![oleiade](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/oleiade/32/35836_2.png) [@oleiade](https://community.grafana.com/u/oleiade)\
**Post date:** [September 6, 2022, 8:24am UTC](https://community.grafana.com/t/support-for-different-timezone/99526/6 "2022-09-06T08:24:11Z")

</div>

Turns out, I found a working solution 🎉

By bundling k6 script(s) in an ES6 project bundled by webpack, I was able to use the [moment-timezone](https://momentjs.com/timezone/) library to get the kind of results you’re looking for.

Assuming you’re working on a unix-like machine, here’s how you can get access to the features you’re looking for:

1. Clone the [k6-template-es6](https://github.com/grafana/k6-template-es6) locally. This is a pre-built template repo to bundle your scripts in a way that would give them access to ES6 features/libraries k6 wouldn’t have access natively to otherwise.
2. Change directory to it.
3. Run `npm install moment-timezone --save`. This will add the [moment-timezone](https://momentjs.com/timezone/) dependency to it.
4. Update the `main.js` (that’s essentially your k6 script) file to use timezones:

```javascript
import moment from "moment-timezone";

export default function () {
  console.log(moment(Date.now()).tz("America/Los_Angeles").format("ha z"));
}

```

1. run `npm run webpack` to produce the bundled code in `build/app.bundle.js`
2. run the bundle using k6 🎉

```auto
INFO[0000] 1am PDT source=console

```

I hope you find this helpful 🙇‍♂️
