There is a time displayed in the upper right corner of the emulator. How can I access this time displayed in the Android emulator?
Asked
Active
Viewed 369 times
0
-
1Simple use **System.currentTimeMillis()** – Piyush Mar 03 '14 at 08:49
-
Calendar now = Calendar.getInstance(); – Srikanth Mar 03 '14 at 09:21
1 Answers
1
it's the same time that is used on the entire OS itself. there are plenty of ways to get it. here are a few:
Date date=new Date();
Calendar calendar=GregorianCalendar.getInstance();
long unixTime=System.currentTimeMillis();
in order to show it nicely, you can use something like:
DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(getApplicationContext());
String formattedTime=timeFormat.format(date);
android.util.Log.d("AppLog", "" + formattedTime);
and the result:

android developer
- 114,585
- 152
- 739
- 1,270
-
1the time displayed in my emulator is different from system time displayed by the OS. – user840930 Mar 03 '14 at 09:04
-
for me it is. sure you've done it as i've written? maybe you need to update your ADT&SDK ? i've updated my answer. – android developer Mar 03 '14 at 11:41
-
I used SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss"); Date date=new Date(); String formattedDate = dateFormat.format(date); and it works. But my emulator time is 1 hour earlier than the OS time. – user840930 Mar 03 '14 at 14:12
-
Can I use something similar to change my emulator time to the time I want? – user840930 Mar 03 '14 at 14:13
-
i don't understand What you mean. maybe try to create a new AVD, and set the time to the correct time (including time zone)? – android developer Mar 03 '14 at 14:19
-
I would like to use the current or existing emulator, but instead of getting the time like we just did, I would like to set the time instead. – user840930 Mar 03 '14 at 15:00
-
set the time via your code? i don't think it's possible using the framework. it should probably be possible by using root, but i don't know how to do it, so i've made a post about it: http://stackoverflow.com/questions/17691850/how-to-change-the-date-on-android-programmatically . please let me know if you've succeeded it. maybe this will help: http://mrothouse.wordpress.com/2007/02/20/setting-datetime-on-unix/ – android developer Mar 03 '14 at 15:15
-
-
it is only an emulator. I am not changing system time, just emulator time. – user840930 Mar 03 '14 at 15:25
-
what do you mean "emulator time"? the emulator has its own OS, so you want to change its OS's time. if you wish, you can (try to) do this via the console of your OS, by using "adb shell" . – android developer Mar 03 '14 at 15:28
-
again, if you wish to do it by code, i don't think it's possible without root. but maybe for the emulator you can do it via "adb shell". – android developer Mar 03 '14 at 15:34