黑马程序员技术交流社区

标题: 答:如何取得年月日,小时分秒 [打印本页]

作者: heshiwei    时间: 2015-10-1 09:18
标题: 答:如何取得年月日,小时分秒
本帖最后由 heshiwei 于 2015-10-1 09:19 编辑

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.
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;
作者: syusouki    时间: 2015-10-1 10:07
学习了,学习
作者: iceknc    时间: 2015-10-1 10:25
又涨姿势了
作者: lostyou    时间: 2015-10-1 11:21
可以的 学习了




欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2