JavaScript中如何获取本周周一到周日分别是几号和几号!日期格式为yyyy-MM-dd

JavaScript中如何获取本周周一到周日分别是几号和几号!日期格式为yyyy-MM-dd,第1张

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 10 Transitional//EN" ">

中文版sql Server中:

Select '本周一',DATEADD(wk, DATEDIFF(wk,0,getdate()), 0)

Select '下周一',DATEADD(wk, DATEDIFF(wk,0,getdate())+1, 0)

Select '本周最末',dateadd(ms,-3,DATEADD(wk, DATEDIFF(wk,0,getdate())+1, 0))

Select '本周五',DATEADD(wk, DATEDIFF(wk,0,getdate()), 0)

Select '本周五末',dateadd(day,-2,dateadd(ms,-3,DATEADD(wk, DATEDIFF(wk,0,getdate())+1, 0)))

/

      获取上周五时间

     /

    public Date lastFirday() {

//作用防止周日得到本周日期

        Calendar calendar = CalendargetInstance();

        while (calendarget(CalendarDAY_OF_WEEK) != CalendarMONDAY) {

            calendaradd(CalendarDAY_OF_WEEK, -1);

        }

        int dayOfWeek = calendarget(CalendarDAY_OF_WEEK) - 1;

        int offset = 7 - dayOfWeek;

        calendaradd(CalendarDATE, offset - 9);

        return DateTimeUtilgetFirstDayOfWeek(calendargetTime(), 6);//这是从上周日开始数的到本周五为6

    }

 

/

      获取上周一时间

     /

    public Date lastMonday() {

        Calendar calendar = CalendargetInstance();

        while (calendarget(CalendarDAY_OF_WEEK) != CalendarMONDAY) {

            calendaradd(CalendarDAY_OF_WEEK, -1);

        }

        int dayOfWeek = calendarget(CalendarDAY_OF_WEEK) - 1;

        int offset = 1 - dayOfWeek;

        calendaradd(CalendarDATE, offset - 7);

        return DateTimeUtilgetFirstDayOfWeek(calendargetTime(), 2);

    }

参考

请采纳,谢谢

获取本周一

 public static Date getNowWeekMonday(Date date) {    

            Calendar cal = CalendargetInstance();    

             calsetTime(date);    

                  

             caladd(CalendarDAY_OF_MONTH, -1); //解决周日会出现 并到下一周的情况    

            calset(CalendarDAY_OF_WEEK, CalendarMONDAY);    

                 

303            return calgetTime();    

        }

获取上周一

public static Date getLastWeekMonday(Date date) {    

             Date a = DateUtilsaddDays(date, -1);    

            Calendar cal = CalendargetInstance();    

            calsetTime(a);    

            caladd(CalendarWEEK_OF_YEAR, -1);// 一周    

            calset(CalendarDAY_OF_WEEK, CalendarMONDAY);    

                  

             return calgetTime();    

        }

获取上周日

public static Date  getLastWeekSunday(Date date) {    

                 

            Date a = DateUtilsaddDays(date, -1);    

           Calendar cal = CalendargetInstance();    

         calsetTime(a);    

           calset(CalendarDAY_OF_WEEK, 1);    

                 

          return calgetTime();    

        }

代码里面有用到 lapachecommon-ang包 你需要下载下 就可以使用

以上就是关于JavaScript中如何获取本周周一到周日分别是几号和几号!日期格式为yyyy-MM-dd全部的内容,包括:JavaScript中如何获取本周周一到周日分别是几号和几号!日期格式为yyyy-MM-dd、1.sql如何通过当前日期获取上周,上上周,上上上周的起始日期(周一_周七)、MSQL如何获取本周周一到周五的时间段等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/10147909.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存