b=(Button) findViewById(R.id.btn);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
// TODO Auto-generated method stub
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
String formattedDate = df.format(c.getTime());
Toast.makeText(MainActivity.this,"Current time => " + formattedDate ,1).show();
}
});
答案 0 :(得分:0)
在一秒钟后重复使用计时器,计时器将运行30秒
new CountdownTimer(30000, 1000) {
public void onTick(long millisUntilFinished) {
Calendar c = Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
String formattedDate = df.format(c.getTime());
Toast.makeText(MainActivity.this,"Current time => " + formattedDate ,1).show();
}
public void onFinish() {
finish();
}
}.start();