前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >JAVA给定两个日期判断是第几周(中…

JAVA给定两个日期判断是第几周(中…

作者头像
用户2192970
发布2019-02-21 17:28:19
1.2K0
发布2019-02-21 17:28:19
举报
文章被收录于专栏:杨飞@益术

public static String getWeekCounterByEventStartDate(String event_s_date, String dailyDate) {         if (isSameWeek(event_s_date, dailyDate)) {             return "WK1";         }         Calendar c_base = Calendar.getInstance();         Calendar c2 = Calendar.getInstance();         Calendar tempC = Calendar.getInstance();         DateFormat df = new SimpleDateFormat("yyyy-MM-dd");         int week = 0;         try {             c_base.setTime(df.parse(event_s_date));             c2.setTime(df.parse(dailyDate));             Long time1 = c2.getTimeInMillis();             Long time2 = c_base.getTimeInMillis();             Long dayDiffer = Math.abs(time1 - time2) / (1000 * 60 * 60 * 24);//毫秒*秒*分*小时             if (dayDiffer.intValue() == 0) {                 week++;                 return "WK" + week;             }             int curTodayWeek = c_base.get(Calendar.DAY_OF_WEEK) - 1;             int differIsWeek = 7 - curTodayWeek;             tempC = (Calendar) c_base.clone();

            if (differIsWeek != 0) {                 week++;             }             if (differIsWeek != 7) {                 tempC.add(Calendar.DAY_OF_YEAR, differIsWeek);             }             time1 = c2.getTimeInMillis();             time2 = tempC.getTimeInMillis();             dayDiffer = Math.abs(time1 - time2) / (1000 * 60 * 60 * 24);//毫秒*秒*分*小时             if (dayDiffer.intValue() == 1) {//差一天                 week++;             } else if (dayDiffer.intValue() < 7) {                 week++;             } else {                 DecimalFormat decimalFormat = new DecimalFormat("#.0");                 String dayNum = decimalFormat.format((double) dayDiffer.intValue() / 7);                 int day = Integer.parseInt(dayNum.substring(0, dayNum.indexOf(".")));                 week += day;                 int dec = Integer.parseInt(dayNum.substring(dayNum.indexOf(".") + 1, dayNum.length()));

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2013年11月11日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档