gpt4 book ai didi

javascript - .getTime 不是函数

转载 作者:行者123 更新时间:2023-12-03 07:09:20 24 4
gpt4 key购买 nike

所以我在比较两个日期时遇到问题。今天存储为 2016-04-17,日期存储为相同的值,只是日期后面有分钟和秒。即使我已将今天存储为日期,today.getTime() 似乎也不起作用。感谢您的帮助。

function getAnswers() {
var Query = new Parse.Query(Surveys);
Query.include("survey");
var today = new Date().toJSON().slice(0, 10);

Query.find({
success: function(objects, results) {

for (var i = 0; i < objects.length; i++) {
var navn = objects[i].get("survey").get("name");
if (navn == "Trening") {
var query = new Parse.Query(SurveyAnswer);
query.descending("createdAt");
query.include("author");
query.equalTo("survey", objects[i]);
query.find({
success: function(results) {

for (var i in results) {
var date = results[i].get("createdAt");
console.log(date.getTime());

console.log(today.getTime());
if (date.getTime() === today.getTime()) {
console.log("Yay");
} else {
console.log("This didn't work");
}


}

最佳答案

您需要将日期转换为 Date 对象。

var date = new Date(results[i].get("createdAt"));

关于javascript - .getTime 不是函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36678547/

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