1

PHPファイルで今日の日付が= 04/01/2013であるかどうかを確認しようとしています。次の JS スクリプトを作成しました。しかし、私はいくつかのエラーが発生しています。理由がわからない。助けてください

//This function will return if today is the date that we are looking for
function isToday($time) // midnight second
{
    alert('1');
    return (strtotime($time) === strtotime('today'));
 }

以下を使用したテスト:

if (isToday('2013-04-01 00:00:00.0') )
{
  alert('Yes true');
}
else
{
  alert("No false');
}

今日の日付 = 04/01/2013 を比較する方法を教えてください。ありがとう。

4

2 に答える 2

3

JavaScript で日付/時刻の比較を行いたい場合は、以前に尋ねられたこの質問を確認することをお勧めします。

PHPのstrtotime()に相当するJavascript?

これは JavaScript の strtotime に相当します。

簡単な例を次に示します。

var d = new Date("2013-04-01");
if(d == new Date()) {
    alert('yes')
} else {
    alert('no')
}
于 2013-01-04T19:15:37.243 に答える
1

PHP の場合:

// Get the time
$serverDate = date('d/m/Y',time());

// Date to check against
$dateToCheck = '04/01/2013';

if($dateToCheck == $serverDate) {
  alert('Yes true');
} else {
  alert('No false');
}
于 2013-01-04T19:16:23.840 に答える