前往小程序,Get更优阅读体验!
立即前往
发布
社区首页 >专栏 >短视频程序,日期选择框前进后退

短视频程序,日期选择框前进后退

原创
作者头像
yunbaokeji柯基
修改2020-11-26 18:13:48
修改2020-11-26 18:13:48
1.1K00
代码可运行
举报
文章被收录于专栏:直播知识直播知识
运行总次数:0
代码可运行

短视频程序,日期选择框前进后退的相关代码

代码语言:javascript
代码运行次数:0
复制
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>demo</title>
</head>
<body>
<button onclick="next()">下一日</button>
<button onclick="nextMonth()">下一月</button>
</body>
<script>
    //下一日
    function next() {
        // day为number,-1:昨天的日期;0:今天的日期;1:明天的日期;
        var day = 1
        var today = new Date('2020-12-31')
        var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day
        today.setTime(targetday_milliseconds) // 注意,这行是关键代码
        var tYear = today.getFullYear()
        var tMonth = today.getMonth()
        var tDate = today.getDate()
        tMonth = this.doHandleMonth(tMonth + 1)
        tDate = this.doHandleMonth(tDate)
        console.log(tYear + '-' + tMonth + '-' + tDate)
    }
    // 下一月
    function nextMonth() {
        var today = new Date('2020-12')
        // day为number,-1:昨天的日期;0:今天的日期;1:明天的日期;
        var day = getCountDays(today)
        var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day
        today.setTime(targetday_milliseconds) // 注意,这行是关键代码
        var tYear = today.getFullYear()
        var tMonth = today.getMonth()
        tMonth = this.doHandleMonth(tMonth + 1)
        console.log(tYear + '-' + tMonth)
    }
    // 格式化数据
    function doHandleMonth(month) {
        var m = month
        if (month.toString().length == 1) {
            m = '0' + month
        }
        return m
    }
    // 获取一个月的天数
    function getCountDays(curDate) {
        // 获取当前月份
        var curMonth = curDate.getMonth()
        // 生成实际的月份: 由于curMonth会比实际月份小1, 故需加1
        curDate.setMonth(curMonth + 1)
        // 将日期设置为0
        curDate.setDate(0)
        // 返回当月的天数
        return curDate.getDate()
    }
</script>
</html>

以上就是短视频程序,日期选择框前进后退的相关代码, 更多内容欢迎关注之后的文章

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

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

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

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

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