# How to change timezone in test step

**URL:** <https://discuss.bitrise.io/t/how-to-change-timezone-in-test-step/858>\
**Category:** Question & Answer\
**Created:** [February 20, 2017, 2:19pm UTC](https://discuss.bitrise.io/t/how-to-change-timezone-in-test-step/858 "2017-02-20T14:19:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![kud-sta](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/kud-sta/32/261_2.png) [@kud-sta](https://discuss.bitrise.io/u/kud-sta)\
**Post date:** [February 20, 2017, 2:19pm UTC](https://discuss.bitrise.io/t/how-to-change-timezone-in-test-step/858/1 "2017-02-20T14:19:49Z")

</div>

In my Pipeline test, it is necessary to change the time zone to Japan compliant.  
Is there a simple way to change the time zone?

---

<div class="post-metadata">

**Author:** ![viktorbenei](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/viktorbenei/32/18_2.png) [@viktorbenei](https://discuss.bitrise.io/u/viktorbenei)\
**Post date:** [February 20, 2017, 2:24pm UTC](https://discuss.bitrise.io/t/how-to-change-timezone-in-test-step/858/2 "2017-02-20T14:24:25Z")

</div>

Hi @kud-sta,

Depends on where you want to set the timezone.

If you want to set the system timezone, you can do that with a **Script** step, just like you would in your Terminal/Command Line.

E.g. in case of macOS: [http://apple.stackexchange.com/questions/117994/is-there-a-fast-way-to-switch-system-time-zone-from-the-command-line](http://apple.stackexchange.com/questions/117994/is-there-a-fast-way-to-switch-system-time-zone-from-the-command-line)

```auto
sudo systemsetup -settimezone timezone

```

Let us know if you have any questions!

---

<div class="post-metadata">

**Author:** ![bootstraponline](https://avatars.discourse-cdn.com/v4/letter/b/c68b51/32.png) [@bootstraponline](https://discuss.bitrise.io/u/bootstraponline)\
**Post date:** [September 14, 2017, 11:15pm UTC](https://discuss.bitrise.io/t/how-to-change-timezone-in-test-step/858/3 "2017-09-14T23:15:37Z")

</div>

This works on macOS

> sudo systemsetup -settimezone America/Denver

On Ubuntu, there’s an error

> sudo timedatectl set-timezone America/Denver
> 
> Failed to create bus connection: No such file or directory

Is there a way to set the timezone on the Ubuntu containers?

Edit: I’m hoping this solution works  
Edit2: nope 😭

> <https://serverfault.com/questions/94991/setting-the-timezone-with-an-automated-script>

---

<div class="post-metadata">

**Author:** ![viktorbenei](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/viktorbenei/32/18_2.png) [@viktorbenei](https://discuss.bitrise.io/u/viktorbenei)\
**Post date:** [September 15, 2017, 12:22pm UTC](https://discuss.bitrise.io/t/how-to-change-timezone-in-test-step/858/4 "2017-09-15T12:22:20Z")

</div>

@bootstraponline what was the issue with [https://serverfault.com/a/94996/221361](https://serverfault.com/a/94996/221361) ?

---

<div class="post-metadata">

**Author:** ![viktorbenei](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/viktorbenei/32/18_2.png) [@viktorbenei](https://discuss.bitrise.io/u/viktorbenei)\
**Post date:** [September 15, 2017, 12:36pm UTC](https://discuss.bitrise.io/t/how-to-change-timezone-in-test-step/858/5 "2017-09-15T12:36:15Z")

</div>

There seem to be an even easier solution, setting the `TZ` environment variable (see e.g. [https://github.com/moby/moby/issues/12084#issuecomment-160265752](https://github.com/moby/moby/issues/12084#issuecomment-160265752)). Not sure if it’s respected by every tool / by the tool you want to use but it certainly is by `date`:

```auto
docker run --rm -it bitriseio/docker-bitrise-base bash

root@eb8b4223062f:/bitrise/src#

$ date
Fri Sep 15 12:29:27 UTC 2017

$ export TZ=Europe/London
$ date
Fri Sep 15 13:31:15 BST 2017

$ export TZ=Europe/Budapest
$ date
Fri Sep 15 14:31:50 CEST 2017

```

You can of course set the `TZ` env as an env var in the bitrise config / `bitrise.yml`, example:

```auto
format_version: "4"
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
project_type: other
app:
  envs:
  - TZ: Europe/Budapest
trigger_map:
- push_branch: '*'
  workflow: primary
- pull_request_source_branch: '*'
  workflow: primary
workflows:
  primary:
    steps:
    - script@1.1.4:
        title: Do anything with Script step
        inputs:
        - content: date

```

Running it in the same docker container as above:

```auto
$ date
Fri Sep 15 12:35:46 UTC 2017

$ bitrise run primary

  ██████╗ ██╗████████╗██████╗ ██╗███████╗███████╗
  ██╔══██╗██║╚══██╔══╝██╔══██╗██║██╔════╝██╔════╝
  ██████╔╝██║ ██║ ██████╔╝██║███████╗█████╗
  ██╔══██╗██║ ██║ ██╔══██╗██║╚════██║██╔══╝
  ██████╔╝██║ ██║ ██║ ██║██║███████║███████╗
  ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝╚══════╝╚══════╝

  version: 1.8.0

INFO[12:35:57] bitrise runs in CI mode           
INFO[12:35:57] Running workflow: primary         

Switching to workflow: primary

+------------------------------------------------------------------------------+
| (0) Do anything with Script step |
+------------------------------------------------------------------------------+
| id: script |
| version: 1.1.4 |
| collection: https://github.com/bitrise-io/bitrise-steplib.git |
| toolkit: bash |
| time: 2017-09-15T12:35:58Z |
+------------------------------------------------------------------------------+
| |
Fri Sep 15 14:35:58 CEST 2017
| |
+---+---------------------------------------------------------------+----------+
| ✓ | Do anything with Script step | 0.51 sec |
+---+---------------------------------------------------------------+----------+

+------------------------------------------------------------------------------+
| bitrise summary |
+---+---------------------------------------------------------------+----------+
| | title | time (s) |
+---+---------------------------------------------------------------+----------+
| ✓ | Do anything with Script step | 0.51 sec |
+---+---------------------------------------------------------------+----------+
| Total runtime: 0.51 sec |
+------------------------------------------------------------------------------+

```

---

<div class="post-metadata">

**Author:** ![bootstraponline](https://avatars.discourse-cdn.com/v4/letter/b/c68b51/32.png) [@bootstraponline](https://discuss.bitrise.io/u/bootstraponline)\
**Post date:** [September 15, 2017, 2:05pm UTC](https://discuss.bitrise.io/t/how-to-change-timezone-in-test-step/858/6 "2017-09-15T14:05:56Z")

</div>

I’m not sure. We are using jest snapshots and no method of changing the timezone is helping. Here’s an example failure:

```
- May 31, 2037 at 11:59 PM
+ Jun 1, 2037 at 5:59 AM

```

The jest tests depend on the system time zone. The mac command works fine, linux one doesn’t.

[https://www.bitrise.io/build/7a47135bdb46c9c0](https://www.bitrise.io/build/7a47135bdb46c9c0)

---

<div class="post-metadata">

**Author:** ![bootstraponline](https://avatars.discourse-cdn.com/v4/letter/b/c68b51/32.png) [@bootstraponline](https://discuss.bitrise.io/u/bootstraponline)\
**Post date:** [September 15, 2017, 2:58pm UTC](https://discuss.bitrise.io/t/how-to-change-timezone-in-test-step/858/7 "2017-09-15T14:58:11Z")

</div>

```auto
#!/usr/bin/env bash -e

rm /etc/timezone   
rm /etc/localtime

TIMEZONE="America/Denver"      
export TZ="$TIMEZONE"
echo "$TIMEZONE" > /etc/timezone                     
cp "/usr/share/zoneinfo/${TIMEZONE}" /etc/localtime 
dpkg-reconfigure -f noninteractive tzdata

```

This is what I’m using now & it worked for me.

```auto
Current default time zone: 'America/Denver'
Local time is now: Fri Sep 15 08:52:42 MDT 2017.
Universal Time is now: Fri Sep 15 14:52:42 UTC 2017.

```

---

<div class="post-metadata">

**Author:** ![viktorbenei](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/viktorbenei/32/18_2.png) [@viktorbenei](https://discuss.bitrise.io/u/viktorbenei)\
**Post date:** [September 18, 2017, 11:26am UTC](https://discuss.bitrise.io/t/how-to-change-timezone-in-test-step/858/8 "2017-09-18T11:26:47Z")

</div>

Glad to hear and thanks for reporting @bootstraponline! 🙂

---

<div class="post-metadata">

**Author:** ![diaa-ghonim2](https://avatars.discourse-cdn.com/v4/letter/d/a6a055/32.png) [@diaa-ghonim2](https://discuss.bitrise.io/u/diaa-ghonim2)\
**Post date:** [August 31, 2023, 4:43pm UTC](https://discuss.bitrise.io/t/how-to-change-timezone-in-test-step/858/9 "2023-08-31T16:43:09Z")

</div>

worked with me 🤙 🤙
