How to change set Emulator time Using APPIUM

Hi I’m trying to set the emulator system time to a predefined date every time i run a test.
I’ve found the command “adb shell date --set=” which changes time but couldnt implement it using appium API’s.
Could you point me out how to implement it or other altenatives.

You can execute this command using JAVA, try like this

public void setEmulatorTime(){

	try {
		   Process rc = Runtime.getRuntime().exec("adb shell date --set=");
		   System.out.println("command execution done");
		  
		InputStream is = rc.getInputStream();
		InputStreamReader isr = new InputStreamReader(is);
		BufferedReader br = new BufferedReader(isr);
		String line;	
		while ((line = br.readLine()) != null) {
		    if (line.length()>0){
			line += br.readLine();
			System.out.println("line: " +  line);
			if (line.contains("Command Output we can check")) {
				System.out.println(" Emulator time set");
				}	
		    }
		}
		
		
		
	}
	catch (Exception e){
		e.printStackTrace();
	}
	finally{}
}

}

Hi thanks for your reply. But appium session is getting cleared when i run Runtime.getRuntime.exec("adb shell date --set=“2017-01-02"”);
I’ve tries to implement it just after I’ve instantiated the AndroidDriver.

Below is the Appium log:
executing cmd: adb -s emulator-5554 shell “echo ‘ping’”
info: [debug] Error: ADB ping failed, returned: * daemon not running. starting it now on port 5037 *

  • daemon started successfully *
    ping
    info: [debug] Stopping logcat capture
    info: [debug] Logcat already stopped
    info: [debug] executing cmd:adb -s emulator-5554 kill-server
    info: [debug] Waiting for device to be ready and to respond to shell commands (timeout = 5)
    info: [debug] executing cmd:adb -s emulator-5554 wait-for-device
    info: [debug] executing cmd: adb -s emulator-5554 shell “echo ‘ready’”
    info: [debug] Starting logcat capture
    info: [debug] Attempting to uninstall app
    info: [debug] Not uninstalling app since server not started with --full-reset
    info: [debug] Cleaning up android objects
    info: [debug] Cleaning up appium session

I am not sure why this is happening.

Can you do one thing if u can automate manual steps to modify emulator date and time

  1. minimize current app
  2. open settings app
  3. select option to change time, save and quit
  4. maximize current app and continue