zoukankan      html  css  js  c++  java
  • 部分基于layui的时间函数

    //        点击昨天

            function checkYesterday() {

                var yesterday = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-' + (myDate.getDate() - 1)////昨天

     

                if (myDate.getDate() == 1) {

                    var yesterday = myDate.getFullYear() + '-' + myDate.getMonth() + '-' + laydate.getEndDate(myDate.getMonth());

                    if (myDate.getMonth() == 0) {

                        var yesterday = myDate.getFullYear() - 1 + '-12-31'

                    }

                }

                console.log(yesterday)

            }

     

            //        点击本周

            function checkThisWeek() {

                var week = myDate.getDay();

                (week == 0) ? 7 : myDate.getDate()//星期几

                var weekStart = myDate.getDate() - (week - 1)

                var weekEnd = myDate.getDate() + 6 - (week - 1)

     

                console.log(week)

                console.log(weekStart)

                console.log(weekEnd)

     

                if (weekStart <= 0) {

                    if (myDate.getMonth() == 0) {

                        currentYear = myDate.getFullYear() - 1;

                        currentMonth = 12

                    } else {

                        currentYear = myDate.getFullYear();

                        currentMonth = myDate.getMonth()

                    }

                    weekStart = weekStart + laydate.getEndDate(myDate.getMonth());

                    weekStart = currentYear + '-' + currentMonth + '-' + weekStart

                    weekEnd = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-' + weekEnd

                } else if (weekEnd > laydate.getEndDate(myDate.getMonth() + 1)) {

                    if (myDate.getMonth() + 1 == 12) {

                        currentYear = myDate.getFullYear() + 1;

                        currentMonth = 1

                    } else {

                        currentYear = myDate.getFullYear();

                        currentMonth = myDate.getMonth() + 1 + 1

                    }

                    weekStart = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-' + weekStart

                    weekEnd = weekEnd - laydate.getEndDate(myDate.getMonth() + 1)

                    weekEnd = currentYear + '-' + currentMonth + '-' + weekEnd

                } else {

                    weekStart = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-' + weekStart

                    weekEnd = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-' + weekEnd

                }

                var currentWeek = weekStart + " - " + weekEnd

                console.log(currentWeek)

     

            }

     

            //        上周

            function checkLastWeek() {

                var week = myDate.getDay();

                (week == 0) ? 7 : myDate.getDate()//星期几

                var weekStart = myDate.getDate() - (week - 1) - 7

                var weekEnd = myDate.getDate() + 6 - (week - 1) - 7

                console.log(weekStart)

                console.log(weekEnd)

     

                if (weekStart <= 0) {

                    if (myDate.getMonth() == 0) {

                        currentYear = myDate.getFullYear() - 1;

                        currentMonth = 12

                    } else {

                        currentYear = myDate.getFullYear();

                        currentMonth = myDate.getMonth()

                    }

                    weekStart = weekStart + laydate.getEndDate(myDate.getMonth());

                    weekStart = currentYear + '-' + currentMonth + '-' + weekStart

                    if (weekEnd <= 0) {

                        weekEnd = weekEnd + laydate.getEndDate(myDate.getMonth());

                        if (myDate.getMonth() == 0) {

                            month = 12

                            year = myDate.getFullYear() - 1

                        } else {

                            month = myDate.getMonth()

                            year = myDate.getFullYear()

                        }

                        weekEnd = year + '-' + month + '-' + weekEnd

                    } else {

                        weekEnd = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-' + weekEnd

                    }

                } else if (weekEnd > laydate.getEndDate(myDate.getMonth() + 1)) {

                    if (myDate.getMonth() + 1 == 12) {

                        currentYear = myDate.getFullYear() + 1;

                        currentMonth = 1

                    } else {

                        currentYear = myDate.getFullYear();

                        currentMonth = myDate.getMonth() + 2

                    }

                    weekEnd = weekEnd - laydate.getEndDate(myDate.getMonth() + 1)

                    weekStart = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-' + weekStart

                    weekEnd = currentYear + '-' + currentMonth + '-' + weekEnd

                } else {

                    weekStart = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-' + weekStart

                    weekEnd = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-' + weekEnd

                }

     

                var lastWeek = weekStart + " - " + weekEnd

     

     

                console.log(lastWeek)

            }

     

            //        本月

            function checkThisMonth() {

                if (laydate.getEndDate(myDate.getMonth() + 1) == 28 || laydate.getEndDate(myDate.getMonth() + 1) == 29) {

                    monthStart = myDate.getFullYear() + '-2-1'

                    monthEnd = myDate.getFullYear() + '-2-' + myDate.getDate()

                } else if (laydate.getEndDate(myDate.getMonth() + 1) == 30) {

                    monthStart = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-1';

                    monthEnd = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-30'

                } else if (laydate.getEndDate(myDate.getMonth() + 1) == 31) {

                    monthStart = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-1';

                    monthEnd = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-31'

                }

                var thisMonth = monthStart + " - " + monthEnd

                console.log(thisMonth)

     

            }

     

      原生的明天

    function tomorrow(date) {

                var date = new Date(date);

                date =date.getTime()+ 24*60*60*1000;

                console.log((new Date(date)));

           

    }

      

  • 相关阅读:
    东拼西凑 vim配置-更新
    oh-my-zsh
    switch变种玩法
    每天一个linux命令(5):rm 命令
    每天一个linux命令(4):mkdir命令
    每天一个linux命令(3):pwd命令
    ES6学习之let
    Window.scrollTo()
    如何调整滚动条的样式
    移动端实现滚动的四种方案
  • 原文地址:https://www.cnblogs.com/wyliunan/p/8831924.html
Copyright © 2011-2022 走看看