用于引导日期选择器 setDate 的日期数组 [英] an Array of date to bootstrap datepicker setDate

查看:49
本文介绍了用于引导日期选择器 setDate 的日期数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个日期数组.从 mysql 数据库中获取并已转换为 js 日期.我从 db 得到的日期被转换成这样的字符串日期.

i have an array of date. got it from mysql database and already converted to js date. the date i got from db are converted to string date like this.

我已经阅读了有关 php 到 js 日期的内容:发送 PHP 日期到javascript日期格式

I've read from this about php to js date : Send PHP date to javascript date Format

假设这是我使用 ajax 并得到响应的 php 日期

let say this is the php date that i use ajax and got response

data = ["Sun Apr 27 2014 22:14:25 +0100","Thu May 29 2014 22:14:25 +0100"]

我有一个全局命名空间.var myDate = {};

i have a global namespace. var myDate = {};

data 数组被转换成这样的 js 日期:

the data array was converted to js date like this:

var arr = [];
$.each(data, function(k,v){
    arr.push = new Date(v);
});
myDate.list = arr;

这是引导日期选择器代码:

this is the bootstrap datepicker code:

$('#bdate').datepicker('setDates', myDate.list);

附加信息:我正在使用 <div id="bdate"></div> 所以它会显示一个内联日期选择器

addtitional info: I'm using <div id="bdate"></div> so it will display an inline datepicker

问题是它似乎没有在选择器上设置日期.

the issue is it seems to be not setting the dates on the picker.

这是小提琴:http://jsfiddle.net/faiz_qlo/jPphC/

推荐答案

是的!最后.我让它工作了!

yes! finally. i got it to work!

var myDate = [];
var data = ["Sun Apr 27 2014 22:14:25 +0100","Thu May 29 2014 22:14:25 +0100"];
var arr = [new Date(2014,05,01), new Date(2014,05,04)]; // just testing

$.each(data, function(k, v){
  var nd = new Date(v);
  var ndd = nd.getDate()-1;
  var ndm = nd.getMonth()+1;
  var ndy = nd.getFullYear();
  var ndg = [parseInt(ndy), parseInt(ndm), parseInt(ndd)];
  myDate.push(new Date(ndg));
  $('#log').append('<div>'+myDate+'</div>');
});

$('#bdate').datepicker('setDates', myDate);

这是小提琴
http://jsfiddle.net/faiz_qlo/jPphC/1/

这篇关于用于引导日期选择器 setDate 的日期数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆