Skip to main content

Change device date and time on BrowserStack real devices

Important: This feature is available only under Device Cloud Pro, Device Cloud Pro + Visual Cloud, and Enterprise Pro plans. On iOS, to access the change date functionality, contact our Support team or Sales team. For more details, check out our pricing page.

You can change the date or time on BrowserStack devices while running an appium test session to test functionalities such as timers, timed notifications or alerts, and more present in your app. App Automate supports this feature through an automated test script.

By default, BrowserStack iOS and Android devices show 24-hour clock format. You can change the device time format to 12-hour clock during a test session to test the related test cases.

In this guide, you will learn about

Supported functionalities on devices and OS

The following table lists the devices and OS versions on which different functionalities are currently supported:

OS Devices OS version Functionality
iOS iPhones and iPads v16 Change device date
iOS iPhones and iPads v13 and above Change device time
Android Phones and tablets v6 and above Change device date and time
iOS iPhones and iPads v15 or above Change device time format (12-hour/24-hour)
Android Phone and tablets v6 and above Change device time format (12-hour/24-hour)
Note: Changing device time format to 12-hour clock is supported on the following Appium versions:
  • iOS: Appium 1.21, 1.22, 2.0.0
  • Android: All Appium versions

Set the device date and time using custom BrowserStack executor

iOS

Set the action type as updateIosDeviceSettings and provide the desired device date and time as input to the argument customDate and customTime respectively in the BrowserStack JavaScript executor to change the device date and time while running the test sessions. To change the device time format to 12-hour clock, use the 12HourTime argument.

The following table lists the allowed input values for customDate, customTime and 12HourTime argument:

Argument Input Format Allowed Values
customDate MMM DD YYYY The date must be within 7 days of the current date.
customTime HH:MM HH allowed values: 00 to 23
MM allowed values: 00 to 59
12HourTime   On: Use this to change the device time format to 12-hour clock.
Off: Use this to change the device time format to 24-hour clock.
By default, the value is set to Off.

Examples

The following code snippet demonstrates how to use the BrowserStack JavaScript executor to change the device date to Sep 15 2023:

JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("browserstack_executor: {
          \"action\":\"updateIosDeviceSettings\", 
          \"arguments\": {
            \"customDate\" : \"Sep 15 2023\"
         }
     }"
);
await driver.execute("browserstack_executor: {
          \"action\":\"updateIosDeviceSettings\", 
          \"arguments\": {
            \"customDate\" : \"Sep 15 2023\"
         }
     }"
);
driver.execute_script("browserstack_executor: {
           \"action\":\"updateIosDeviceSettings\", 
          \"arguments\": {
            \"customDate\" : \"Sep 15 2023\"
         }
     }"
);
caps["javascriptEnabled"] = "true" #include this capability for JavaScript executors to work
driver.execute_script("browserstack_executor: {
          \"action\":\"updateIosDeviceSettings\", 
          \"arguments\": {
            \"customDate\" : \"Sep 15 2023\"
         }
     }"
);
((IJavaScriptExecutor)driver).ExecuteScript("browserstack_executor: {
          \"action\":\"updateIosDeviceSettings\", 
          \"arguments\": {
            \"customDate\" : \"Sep 15 2023\"
         }
     }"
);
Note: You can change the date up to 7 days in the future from the current date. You can do this through a single executor command or multiple executor commands.

The following code snippet demonstrates how to use the BrowserStack JavaScript executor to change the device time to 14:05:

JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("browserstack_executor: {
          \"action\":\"updateIosDeviceSettings\", 
          \"arguments\": {
            \"customTime\" : \"14:05\"
         }
     }"
);
await driver.execute("browserstack_executor: {
          \"action\":\"updateIosDeviceSettings\", 
          \"arguments\": {
            \"customTime\" : \"14:05\"
         }
     }"
);
driver.execute_script("browserstack_executor: {
           \"action\":\"updateIosDeviceSettings\", 
          \"arguments\": {
            \"customTime\" : \"14:05\"
         }
     }"
);
caps["javascriptEnabled"] = "true" #include this capability for JavaScript executors to work
driver.execute_script("browserstack_executor: {
          \"action\":\"updateIosDeviceSettings\", 
          \"arguments\": {
            \"customTime\" : \"14:05\"
         }
     }"
);
((IJavaScriptExecutor)driver).ExecuteScript("browserstack_executor: {
          \"action\":\"updateIosDeviceSettings\", 
          \"arguments\": {
            \"customTime\" : \"14:05\"
         }
     }"
);

The following code snippet demonstrates how to change the device time format to 12-hour clock:

JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("browserstack_executor: {
          \"action\":\"updateIosDeviceSettings\", 
          \"arguments\": {
            \"12HourTime\" : \"On\"
         }
     }"
);
await driver.execute("browserstack_executor: {
          \"action\":\"updateIosDeviceSettings\", 
          \"arguments\": {
            \"12HourTime\" : \"On\"
         }
     }"
);
driver.execute_script("browserstack_executor: {
           \"action\":\"updateIosDeviceSettings\", 
          \"arguments\": {
            \"12HourTime\" : \"On\"
         }
     }"
);
caps["javascriptEnabled"] = "true" #include this capability for JavaScript executors to work
driver.execute_script("browserstack_executor: {
          \"action\":\"updateIosDeviceSettings\", 
          \"arguments\": {
             \"12HourTime\" : \"On\"
         }
     }"
);
((IJavaScriptExecutor)driver).ExecuteScript("browserstack_executor: {
          \"action\":\"updateIosDeviceSettings\", 
          \"arguments\": {
            \"12HourTime\" : \"On\"
         }
     }"
);

Android

Set the action type as updateAndroidDeviceSettings and provide the desired device date and time as input to the argument customDate and customTime respectively in the BrowserStack JavaScript executor to change the device date and time while running the test sessions. To change the device time format to 12-hour clock, use the 12HourTime argument.

The following table lists the allowed input values for customDate, customTime, and 12HourTime arguments:

Argument Input Format Allowed Values
customDate MMM DD YYYY MMM allowed values: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec
DD allowed values: 01 to 31
YYYY allowed values: 2015 to 2035
customTime HH:MM HH allowed values: 00 to 23
MM allowed values: 00 to 59
12HourTime   On: Use this to change the device time format to 12-hour clock.
Off: Use this to change the device time format to 24-hour clock.
By default, the value is set to Off.

Examples

The following code snippet demonstrates how to use the BrowserStack JavaScript executor to change the device date to Sep 15 2023:

JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("browserstack_executor: {
          \"action\":\"updateAndroidDeviceSettings\", 
          \"arguments\": {
            \"customDate\" : \"Sep 15 2023\"
         }
     }"
);
await driver.execute("browserstack_executor: {
          \"action\":\"updateAndroidDeviceSettings\", 
          \"arguments\": {
            \"customDate\" : \"Sep 15 2023\"
         }
     }"
);
driver.execute_script("browserstack_executor: {
           \"action\":\"updateAndroidDeviceSettings\", 
          \"arguments\": {
            \"customDate\" : \"Sep 15 2023\"
         }
     }"
);
caps["javascriptEnabled"] = "true" #include this capability for JavaScript executors to work
driver.execute_script("browserstack_executor: {
          \"action\":\"updateAndroidDeviceSettings\", 
          \"arguments\": {
            \"customDate\" : \"Sep 15 2023\"
         }
     }"
);
((IJavaScriptExecutor)driver).ExecuteScript("browserstack_executor: {
          \"action\":\"updateAndroidDeviceSettings\", 
          \"arguments\": {
            \"customDate\" : \"Sep 15 2023\"
         }
     }"
);

The following code snippet demonstrates how to use the BrowserStack JavaScript executor to change the device time to 14:05:

JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("browserstack_executor: {
          \"action\":\"updateAndroidDeviceSettings\", 
          \"arguments\": {
            \"customTime\" : \"14:05\"
         }
     }"
);
await driver.execute("browserstack_executor: {
          \"action\":\"updateAndroidDeviceSettings\", 
          \"arguments\": {
            \"customTime\" : \"14:05\"
         }
     }"
);
driver.execute_script("browserstack_executor: {
           \"action\":\"updateAndroidDeviceSettings\", 
          \"arguments\": {
            \"customTime\" : \"14:05\"
         }
     }"
);
caps["javascriptEnabled"] = "true" #include this capability for JavaScript executors to work
driver.execute_script("browserstack_executor: {
          \"action\":\"updateAndroidDeviceSettings\", 
          \"arguments\": {
            \"customTime\" : \"14:05\"
         }
     }"
);
((IJavaScriptExecutor)driver).ExecuteScript("browserstack_executor: {
          \"action\":\"updateAndroidDeviceSettings\", 
          \"arguments\": {
            \"customTime\" : \"14:05\"
         }
     }"
);

The following code snippet demonstrates how to change the device time format to 12-hour clock:

JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("browserstack_executor: {
          \"action\":\"updateAndroidDeviceSettings\", 
          \"arguments\": {
            \"12HourTime\" : \"On\"
         }
     }"
);
await driver.execute("browserstack_executor: {
          \"action\":\"updateAndroidDeviceSettings\", 
          \"arguments\": {
            \"customDate\" : \"Sep 15 2023\",
            \"12HourTime\" : \"On\"
         }
     }"
);
driver.execute_script("browserstack_executor: {
           \"action\":\"updateAndroidDeviceSettings\", 
          \"arguments\": {
            \"12HourTime\" : \"On\"
         }
     }"
);
caps["javascriptEnabled"] = "true" #include this capability for JavaScript executors to work
driver.execute_script("browserstack_executor: {
          \"action\":\"updateAndroidDeviceSettings\", 
          \"arguments\": {
            \"12HourTime\" : \"On\"
         }
     }"
);
((IJavaScriptExecutor)driver).ExecuteScript("browserstack_executor: {
          \"action\":\"updateAndroidDeviceSettings\", 
          \"arguments\": {
            \"12HourTime\" : \"On\"
         }
     }"
);

Check this page for a list of various JavaScript Executors that BrowserStack offers.

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better

Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback!

Talk to an Expert
Download Copy