Javascript에서 지정된 날짜를 얻는 방법

PHPz
풀어 주다: 2018-10-10 17:51:17
앞으로
1080명이 탐색했습니다.

这篇文章主要介绍了Javascript中获取指定日期的方法,感兴趣的朋友可以参考一下,希望对你有所帮助!

实现设计:

Step1:获取指定时间的日期数据

Step2:用当前起止时间进行搜索

代码实现:

1.定义日期格式化方法:

Date.prototype.Format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份
        "d+": this.getDate(), //日
        "h+": this.getHours(), //小时
        "m+": this.getMinutes(), //分
        "s+": this.getSeconds(), //秒
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度
        "S": this.getMilliseconds() //毫秒
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
로그인 후 복사

2.根据日期差获取指定日期数据:

function getdate(days) {
    var now = new Date();
    var date = new Date(now.getTime() - days * 24 * 3600 * 1000);
    var dates = date.Format('yyyy-MM-dd');
    return dates;
}
로그인 후 복사

3.获取不同制定时间的日期数据并赋值给起始日历框:

function today_btn() {
    var today = getdate(0);
    var tomorrow = getdate(-1);
    document.getElementById("startdate").value = today;
    document.getElementById("enddate").value = tomorrow;
}

function yestoday_btn() {
    var today = getdate(0);
    var yestoday = getdate(1);
    document.getElementById("startdate").value = yestoday;
    document.getElementById("enddate").value = today;
}
로그인 후 복사

接下来的事情就是用获取到的日期进行数据请求了。

更多相关教程亲访问  JavaScript视频教程

관련 라벨:
원천:csdn.net
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!