Android: how to change the time in emulator?
I've noticed that the time in my emulator for android projects is w开发者_如何学编程rong. Its one hour behind. How do I go about changing the time and can I do it in eclipse?
Run>Debug Configurations/Run Configurations
Tab Target> Additional Emulator Command Line Options
-timezone America/New_York
use this command
C:\> adb shell
#date –- 2009-10-01 14:24:59
20070325.123456
#date –s 20070325.123456
I believe the emulator is set to the GMT timezone by default. You can specify the timezone for the emulator with the -timezone
parameter.
https://developer.android.com/studio/run/emulator-commandline.html
If you want to change date & time, from running emulator window go to:
Apps -> Settings -> Date & Time -> Disable Automatic date & time -> Set date & Set time
If you want to change timezone, from running emulator window go to:
Apps -> Settings -> Date & Time -> Disable Automatic time zone -> Select time zone
If you use IntelliJ you can do that from Run/Edit Configurations window. Go to Emulator tab and add this to "Additional command line options":
-timezone Europe/Helsinki
Android document gives this info:
-timezone Set the timezone for the emulated device to , instead of the host's timezone. must be specified in zoneinfo format. For example: "America/Los_Angeles" "Europe/Paris"
Zoneinfo format is also known as tz database. So to find you specific timezone, you can use the Wikipedia list here:
http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
Increase emulator date by some certain hours, Perfectly working Here i am increasing time by 4 hours.
adb root
adb shell "date date +09190400
"
Month & Date : 0919(mmdd) hours : 04
I have searched extensively, and it seems like the only option is to turn off the Auto-Set time in the emulator phone prefs, and manually set the timezone. I can't find any place to set emulator
options from inside Eclipse/AVD Manager.
Set the time on the emulator via ADB:
Bash:
adb root
adb shell "date $(date +%m%d%H%M%G.%S)"
adb shell "am broadcast -a android.intent.action.TIME_SET"
Powershell:
$currentDate = Get-Date -Format "MMddHHmmyyyy.ss" # Android's preferred format
adb root
adb shell "date $currentDate"
adb shell "am broadcast -a android.intent.action.TIME_SET"
The am broadcast
signal the clock to update in the status-bar, though its not needed according to my tests on emulator API-31.
The adb root
lets following adb command execute with root-access, which is needed to set the date.
Thanks to RipTutorial
See also duplicate Stackoverflow with more info for special android-devices: Set date/time using ADB shell
refer to this page
http://ysl-paradise.blogspot.com/2008/09/android.html
in the comment part.
The question was 9 years ago, but these days (on a mac at least) you just change your mac's time in the OSX System Preferences Date & Time pane and it's immediately mirrored in the Android emulator.
精彩评论