Reputation: 118
I have this code for my splash screen
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
startActivity(new Intent(Splash.this, Home.class));
Log.i(TAG, "Exiting Splash Screen");
finish();
}
}, TIMEOUT_TIME);
is it possible to get what is the current time at TIMEOUT_TIME from inside the run(){}?
Upvotes: 0
Views: 3633
Reputation: 2825
To be more precise, I would use nanoTime() method rather than currentTimeMillis():
long startTime = System.nanoTime();
myCall();
long stopTime = System.nanoTime();
System.out.println(stopTime - startTime);
Upvotes: 0
Reputation: 3372
Using this function you will get current time at timeout.
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd_HHmmss");
String currentDateandTime = sdf.format(new Date());
Log.e("Demo","==================================="+currentDateandTime);
}
}, 3000);
Upvotes: 0
Reputation: 13588
AFAIK, Handler doesn't provide any convenient method to do this. You have to save the initial time and calcualte elapsed time. Like this.
Upvotes: 1