gpt4 book ai didi

javascript - 如何使用日期字符串并检查它是否是今天

转载 作者:行者123 更新时间:2023-12-02 16:33:25 25 4
gpt4 key购买 nike

如何使用日期字符串并检查它是否是今天

我有以下隐藏字段:

<input type="hidden" id="datThe" value="01192015" />

如何检查 01192015 是否是今天。

更新(不起作用):

<input type="hidden" value="closeHuguenot" id="statHuguenot" />
<input type="hidden" value="01232015" id="dateHuguenot" />

$(function () {
var date = new Date(); // Initiate a new date object
var day = date.getDate(); // Gets the current day
day = (day.length < 2) ? day : '0' + day; // This will add 0 before the date if its less than 10
var month = date.getMonth() + 1; // Because js months starts at 0
month = (month.length < 2) ? month : '0' + month; // Will add 0 before the month if less than 10
var year = date.getFullYear(); // Gets the current year
var formatted_date = month + day + year; // Puts them together as your date is formatted

var sHuguenot = $("#statHuguenot").val();
var dHuguenot = $("#dateHuguenot").val();
if (sHuguenot.toLowerCase() == "closehuguenot" && dHuguenot == formatted_date.toString()) {
$("#Label171").html("CLOSED"); //not displaying closed...
}
});

最佳答案

var date = new Date(); // Initiate a new date object
var day = date.getDate(); // Gets the current day
day = ( day > 10 ) ? day : '0' + day; // This will add 0 before the date if its less than 10
var month = date.getMonth()+1; // Because js months starts at 0
month = ( month > 10 ) ? month : '0' + month; // Will add 0 before the month if less than 10
var year = date.getFullYear(); // Gets the current year
var formatted_date = month + day + year; // Puts them together as your date is formatted

// Check if the current date is equal to your input value
if( document.getElementById('datThe').value == formatted_date.toString() ){
alert( ' The date is today ' );
}

关于javascript - 如何使用日期字符串并检查它是否是今天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28118098/

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