您好,欢迎访问一九零五行业门户网

Javascrip中t获取指定日期的方法

这篇文章主要介绍了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视频教程
其它类似信息

推荐信息