Fix the time from DigitalClock?

Total Post:36


 1291  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?
  1. Re: Fix the time from DigitalClock?

    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(;

      Modified On Apr-06-2018 12:13:27 AM
  1. Re: Fix the time from DigitalClock?

    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();

      Modified On Apr-06-2018 12:12:50 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.