---
title: "Obtain current timezone in Selenium IDE using JS"
description:
  "Obtaining current time from a different timezone using javascript in selenium
  IDE"
canonical_url: "https://www.bigbinary.com/blog/how-to-obtain-current-time-from-a-different-timezone-in-selenium-ide-using-javascript"
markdown_url: "https://www.bigbinary.com/blog/how-to-obtain-current-time-from-a-different-timezone-in-selenium-ide-using-javascript.md"
---

# Obtain current timezone in Selenium IDE using JS

Obtaining current time from a different timezone using javascript in selenium
IDE

- Author: Prabhakar Battula
- Published: January 8, 2015
- Categories: JavaScript

I had encountered a problem in one of our projects where it was required to
obtain the current time from a different timezone and then use it. I am in IST
(Indian Standard Timezone - 5.50) and was required to get the time in EST
(Eastern Standard Timezone + 5.00)

These are the set of commands I used to achieve that.

```javascript

Command : storeEval
Target  : var d = new Date();
          d.setTime(new Date( (d.getTime() + (d.getTimezoneOffset() * 60000))            + (3600000 * (-5) ) ));
          d.toLocaleTimeString();
Value   : timeEst

Command : echo
Target  : ${timeEst}
Value   :

```

**`storeEval`** command is used to store the value in the variable `timeEst`
after evaluating the javascript code.

**`var d = new Date();`** a new date object is created.

**`d.getTime()`** method returns the number of _milliseconds_ between midnight
of January 1, 1970 and the specified date (as is present in the variable "d").

**`d.getTimezoneOffset()`** method returns the time difference between UTC
(Coordinated Universal Time) time and local time from the variable "d", in
_minutes_. For example, If our time zone is GMT-5.50, -330 will be returned.

Since `getTime()` is in milliseconds and `getTimezoneOffset()` is in minutes;
`getTimezoneOffset()` is multiplied with 60000 to make it into milliseconds.

The expression **`3600000 * (- 5)`** is required to make the time from UTC to
EST. The difference between UTC and EST is -5 hours. So, to make the hours to
milliseconds we need to multiply with 3600000 (60 min x 60 sec x 1000 millisec).

**`d.setTime()`** method is used to set the time of variable "d" after
evaluating the expression.

With the above, the variable "d" is set with the date and time of the EST time.

**`d.toLocaleTimeString()`** method returns the time portion of a Date object as
a string, using locale conventions.

The time string obtained above is stored in the variable `timeEst`.

**`echo ${timeEst}`**, the time string is displayed in the console.

---

**`Using est time`**

![Selenkum javascript EST time](https://www.bigbinary.com/blog/images/images_used_in_blog/2015/how-to-obtain-current-time-from-a-different-timezone-in-selenium-ide-using-javascript/selenium_javascript_time.jpg)

---

**`Using est date`**

![Selenkum javascript EST date](https://www.bigbinary.com/blog/images/images_used_in_blog/2015/how-to-obtain-current-time-from-a-different-timezone-in-selenium-ide-using-javascript/selenium_javascript_date.jpg)

---

## Links

- [Human page](https://www.bigbinary.com/blog/how-to-obtain-current-time-from-a-different-timezone-in-selenium-ide-using-javascript)
