Android获取当前时间的3中方法总结

mac2022-06-30  22

今天听了一在线公开课,任务是做一个数字时钟,其中最关键的自然是获取当前的系统时间。做个简单的记录,如下:

1. 

Time time = new Time("GMT+8"); time.setToNow(); //Sets the time of the given Time object to the current time. 将事件获取对象置为当前时间 System.out.println(time.hour); System.out.println(time.minute); System.out.println(time.second);

2.

private SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); String str = sdf.format(new Date());

3.

Calendar calendar = Calendar.getInstance(); int hour = calendar.HOUR_OF_DAY; int minute = calendar.MINUTE; int second = calendar.SECOND;

  

转载于:https://www.cnblogs.com/hoosway/p/4836701.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)