时间格式及Calendar的用法
发布日期:2022-03-11 15:03:38 浏览次数:9 分类:技术文章

本文共 549 字,大约阅读时间需要 1 分钟。

确定时间格式

SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMddHHmmss");

SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

Date currentTime = new Date();

Date类型转换成String类型

String dateString = sdf.format(currentTime);

String类型转换成Date类型

Date date = sdf.parse(dateString);

calendar 用法实例

Calendar calendar = Calendar.getInstance();

calendar.setTime(sdf.parse(Btime));

calendar.add(Calendar.DATE, 5);//在calendar加5天,如果是-5就是在calendar减5天

String time = sdf.format(calendar.getTime());//将Date类型转换成String类型

转载于:https://www.cnblogs.com/jassy/p/6774361.html

转载地址:https://blog.csdn.net/weixin_30267785/article/details/99184474 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:java实现floyd统计天津地铁的网站距离
下一篇:codevs5037 线段树练习4加强版(暴力分块)

发表评论

最新留言

表示我来过!
[***.240.166.169]2024年04月12日 22时06分11秒