两个时间之间的有多少个工作日,有多少天,有多少天的周末

编程入门 行业动态 更新时间:2024-10-25 14:33:15

两个时间之间的<a href=https://www.elefans.com/category/jswz/34/1769442.html style=有多少个工作日,有多少天,有多少天的周末"/>

两个时间之间的有多少个工作日,有多少天,有多少天的周末

不愿说废话直接上代码

 private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");int count = 0;public static void main(String[] args) throws ParseException {String sTime = "2020-12-28";String eTime = "2021-02-12";List gongzuori = gongzuori(sTime, eTime);for (Object o : gongzuori) {System.out.println(o.toString());}}public static List gongzuori(String sTime, String eTime) throws ParseException {//工作日计数器int count = 0;//周末计数器int count2 = 0;//开始时间转格式Date parse = sdf.parse(sTime);//结束时间转格式Date parse2 = sdf.parse(eTime);//中间相差多少天int time = (int) ((parse2.getTime() - parse.getTime()) / 1000 / 60 / 60 / 24);ArrayList<Object> list = new ArrayList<>();Calendar calendar = Calendar.getInstance();for (int i = 0; i < time; i++) {//获取第i天的日期calendar.setTime(new Date());calendar.add(Calendar.DAY_OF_MONTH, +i);Date date = calendar.getTime();//获取本周第几天int i1 = calendar.get(Calendar.DAY_OF_WEEK);//1是周日 7是周六if (i1 == 1 || i1 == 7) {count2++;list.add("时间:" + sdf.format(date) + "是周末");} else {count++;list.add("时间:" + sdf.format(date) + "不是周末");}list.add("工作日共有" + count+"天");list.add("周末共有" + count2+"天");list.add("之间共有"+time+"天");}return list;}

更多推荐

两个时间之间的有多少个工作日,有多少天,有多少天的周末

本文发布于:2023-06-27 19:09:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/915719.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:有多少   工作日   有多少个   周末   两个

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!