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?
Fix the time from DigitalClock?
2072
14-Oct-2014
Updated on 14-Oct-2014
Takeshi Okada
14-Oct-2014String 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();
Anonymous User
14-Oct-2014public 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 ;
}
@Override
public void onCreate() {
super.onCreate();
sInstance = this;
time = System.currentTimeMillis();
}
}