- Related Questions & Answers
Feb 02, 2018 Method 1: 1. Go to Settings - Click on App Info - Click on the desired App Name You can see the date when this app was installed in the 'Data Used' column. Beautiful Widgets is one of the best date and time widgets for Android. Even though it has a variety of offerings when it comes to widgets, its focus on including some of the best date and time widgets for Android lands it in this list. However, one complaint that several users have had is its effect on battery life. Download: Beautiful Widgets Free.
- Selected Reading
As per Oracle documentation, SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. In this example, we have imported simple date format class from java as shown below -
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.
Step 2 − Add the following code to res/layout/activity_main.xml.
In the above code, we have given text view, it going to print the current date on the window manager.
Step 3 − Add the following code to src/MainActivity.java
In the above code we are calling SimpleDateFormat and from the simpledateformat, we are accessing the current date in the string. There are so many date format are available. For more reference Click here.
Step 4 − No need to change manifest.xml.
Let's try to run your application. I assume you have connected your actual Android Mobile device with your computer. To run the app from an android studio, open one of your project's activity files and click Run from the toolbar. Select your mobile device as an option and then check your mobile device which will display your default screen −
In the above example, it contains a current date and time.
Click here to download the project code
Active10 days ago
When you want to change the mobile system date or time in your application, how do you go about doing it?
App For Date And Time
marcc10.6k77 gold badges4444 silver badges5757 bronze badges
6 Answers
You cannot on a normal off the shelf handset, because it's not possible to gain the SET_TIME permission. This permission has the protectionLevel of
signatureOrSystem
, so there's no way for a market app to change global system time (but perhaps with black vodoo magic I do not know yet).You cannot use other approaches because this is prevented on a Linux level, (see the long answer below) - this is why all trials using terminals and SysExecs gonna fail.
If you CAN gain the permission either because you rooted your phone or built and signed your own platform image, read on.
Short Answer
It's possible and has been done. You need
android.permission.SET_TIME
. Afterward use the AlarmManager
via Context.getSystemService(Context.ALARM_SERVICE)
and it s method setTime()
.Snippet for setting the time to 2010/1/1 12:00:00 from an Activity or Service:
If you which to change the timezone, the approach should be very similar (see
android.permission.SET_TIME_ZONE
and setTimeZone
)Long Answer
As it has been pointed out in several threads, only the
system
user can change the system time. This is only half of the story. SystemClock.setCurrentTimeMillis()
directly writes to /dev/alarm
which is a device file owned by system
lacking world writeable rights. So in other words only processes running as system
may use the SystemClock
approach. For this way android permissions do not matter, there's no entity involved which checks proper permissions.This is the way the internal preinstalled Settings App works. It just runs under the
system
user account. For all the other kids in town there's the alarm manager. It's a system service running in the
system_server
process under the - guess what - system
user account. It exposes the mentioned setTime
method but enforces the SET_TIME
permission and in in turn just calls SystemClock.setCurrentTimeMillis
internally (which succeeds because of the user the alarm manager is running as).Cheers
Hitesh Sahu18.9k99 gold badges9797 silver badges8989 bronze badges
jekjek2,32611 gold badge1616 silver badges2626 bronze badges
According to this thread, user apps cannot set the time, regardless of the permissions we give it. Instead, the best approach is to make the user set the time manually. We will use:
Unfortunately, there is no way to link them directly to the time setting (which would save them one more click). By making use of ellapsedRealtime, we can ensure that the user sets the time correctly.
Community♦
CasebashCasebash51.6k7676 gold badges219219 silver badges327327 bronze badges
A solution for rooted devices could be execute the commands
- su
- date -s YYYYMMDD.HHMMSS
You can do this by code with the following method:
Just call the previous method like this:
Led MachineLed Machine4,16111 gold badge2727 silver badges3535 bronze badges
Date Time App For Android Tv
I didn't see this one on the list anywhere but it works for me. My device is rooted and I have superuser installed, but if superuser works on non-rooted devices, this might work. I used an AsyncTask and called the following:
SlopesSlopes
In our application case, the dirty workaround was:
When the user is connected to Internet, we get the Internet Time (NTP server) and compare the difference (-) of the internal device time (registederOffsetFromInternetTime). We save it on the config record file of the user.
We use the time of the devide + registederOffsetFromInternetTime to consider the correct updated time for OUR application.
All GETHOUR processes check the difference between the actual time with the time of the last comparission (with the Internet time). If the time over 10 minutes, do a new comparission to update registederOffsetFromInternetTime and mantain accuracy.
If the user uses the App without Internet, we can only use the registederOffsetFromInternetTime stored as reference, and use it. Just if the user changes the hour in local device when offline and use the app, the app will consider incorrect times. But when the user comes back to internet access we warn he about the clock changed , asking to resynchronize all or desconsider updates did offline with the incorrect hour.
Vinicius SchneiderVinicius Schneider
thanks penquin. In quickshortcutmaker I catch name of date/time seting activity exactly. so to start system time setting:
`
Date Time App For Android Phones
barabek_AND_40_chelovek_Ltdbarabek_AND_40_chelovek_Ltd