标签:
今天听了一在线公开课,任务是做一个数字时钟,其中最关键的自然是获取当前的系统时间。做个简单的记录,如下:
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;
标签:
原文地址:http://www.cnblogs.com/hoosway/p/4836701.html