gpt4 book ai didi

javascript - 日期时间解析器函数不断返回星期二的天数

转载 作者:行者123 更新时间:2023-12-03 10:15:47 26 4
gpt4 key购买 nike

出于某种原因,我的日期时间解析器始终返回星期二的日期,知道为什么吗?

例如:

<div class="datetime">2015-06-04 16:00:00</div>
<div class="datetime">2015-06-05 13:00:00</div>

输出

Tuesday 04 June - 16:00
Tuesday 05 June - 13:00

代码

HTML

<div class="datetime">2015-06-04 16:00:00</div>
<div class="datetime">2015-06-05 13:00:00</div>

JS

$('.datetime').each(function () {
var value = $(this).text().trim().split(' '),
date = value[1].split(':'),
day = value[0].split('-'),
days = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'],
months = ['January','February','March','April','May','June','July','August','September','October','November','December'];
date.pop();
$(this).html(days[new Date(Date.parse('2015-05-04')).getDay()] +' '+day[2]+' '+ months[new Date(Date.parse(value[0])).getMonth()] + ' - ' + date[0] + ':' + date[1]);
});

Jsfiddle 链接

http://jsfiddle.net/bh5s7jdt/

最佳答案

您已经给出了硬编码日期!将其更改为:value[0]

Working Demo

$(this).html(days[new Date(Date.parse(value[0])).getDay()] +' '+day[2]+' '+   
months[new Date(Date.parse(value[0])).getMonth()] + ' - ' + date[0] + ':' + date[1]);

关于javascript - 日期时间解析器函数不断返回星期二的天数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29876474/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com