Home > DeveloperSection > Forums > Fix the time from DigitalClock?
Pawan Shukla

Total Post:37

Posted on    October-14-2014 1:03 AM

 Android Android  Mobile Development 

 2 Reply(s)
 577  View(s)
Rate this:
For example, I have DigitalClock and TextView in MainActivity. How to fix time in TextView (24-hour format) in a moment of time when the Application is launched?

Kamlakar Singh
Kamlakar Singh

Total Post:194

Posted on    October-14-2014 1:04 AM

public class ApplicationController extends Application{

         * A singleton instance of the application class for easy access in other places
        private static ApplicationController sInstance;

        public static synchronized ApplicationController getInstance() {
            return sInstance;

       private String time ;

       public String getTime(){

          return time ;


        public void onCreate() {
              sInstance = this;
              time = System.currentTimeMillis();


Then you can just setText.

TextView tx = findViewById(R.id.your_id);

Takeshi Okada
Takeshi Okada

Total Post:89

Posted on    October-14-2014 1:10 AM

You can try this :

String time= "Time : "  + DateFormat.getTimeFormat(getContext()).format(new Date(calendar.getTimeInMillis()));

This will return to the user smth like : " Time : 13:11"

Assuming you are using an instance of calendar somewhere in your code.

If not simply get an instance of calendar like this (it will return current device time ) :

Calendar calendar = Calendar.getInstance();

Don't want to miss updates? Please click the below button!

Follow MindStick