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

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

1. orm

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.blog

Calendar calendar = Calendar.getInstance();

int hour = calendar.HOUR_OF_DAY;
int minute = calendar.MINUTE;
int second = calendar.SECOND;
相关文章
相关标签/搜索