获得Day" Thursday"从2015-08-01开始,这是从日历来的

时间:2015-01-08 14:47:45

标签: javascript

朋友我有一个输入字段,我在其中显示正在显示并完美运行的datepicker日历。像这样的文本字段字段日期2015-08-01。我想要这个日期格式,我也希望从这个日期得到像“星期四”这样的日子,我希望你明白我的观点。 当我点击日历中的任何日期时,它会在输入字段中显示2015-08-01这样的日期,并且我在变更和保存变量时使用此字段然后我尝试从中获取日但是失败了。这是我尝试的代码

 var d = new Date();
 var n = String(d.getDay());
 alert(n);

也是这个

var d = new Date();
var days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
alert( days[d.getDay()] ) ;

1 个答案:

答案 0 :(得分:2)

试试这段代码希望这会有效 HTML

<p>Date: <input type="text" id="datepicker"></p>

的JavaScript

$( "#datepicker" ).datepicker( {
     onSelect: function(dateText, inst) {
        var date = $(this).val();
         var d = new Date(date+" UTC");
alert(days[d.getDay()]);
     }
    });
var days = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];

js Fiddle Click