java 时间只取[时分]的写法

来源:互联网 发布:js获取两位数月份 编辑:程序博客网 时间:2024/06/05 16:17

1、SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm");

根据类似的思路,可知道只取分的写法为

SimpleDateFormat dateFormat = new SimpleDateFormat("mm");

其余写法同理

2、使用calender取下5分钟时间

Calendar nowTime = Calendar.getInstance();
nowTime.add(Calendar.MINUTE, 5);
SimpleDateFormat dateFormat = new SimpleDateFormat(
"mm");
String time_after_5Min = dateFormat.format(nowTime.getTime());

如果有其他的需求可看jdk API的calender类的说明


0 0
原创粉丝点击