Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Javascript中以与在PHP中相同的方式存储时间_Javascript_Php_Date_Time - Fatal编程技术网

在Javascript中以与在PHP中相同的方式存储时间

在Javascript中以与在PHP中相同的方式存储时间,javascript,php,date,time,Javascript,Php,Date,Time,PHP的工作原理如下 <?php $x = ""; $now = gmdate('H:i'); $one = "22:30"; $timenow = strtotime($now); $timeone = strtotime($one); if ($timenow > $timeone) { $x = "time now is more than time one"; } elseif ($timenow < $timeone) { $x = "time now is

PHP的工作原理如下

<?php
$x = "";
$now = gmdate('H:i');
$one = "22:30";

$timenow = strtotime($now);
$timeone = strtotime($one);

if ($timenow > $timeone) 
{
 $x = "time now is more than time one";
}
elseif ($timenow < $timeone)
{
 $x = "time now is less than time one";
}
?>

现在来看Javascript

var date = new Date();
var hour = date.getHours();
var minute = date.getMinutes();
var now = hour + ":" + minute;
var one = "22:30";
var x = "";

if (now > one)
{
 x = "time now is more than time one";
}
if (now < one)
{
 x = "time now is less than time one";
}
var-date=新日期();
var hour=date.getHours();
var minute=date.getMinutes();
var now=小时+“:”+分钟;
var one=“22:30”;
var x=“”;
如果(现在>一个)
{
x=“现在的时间不止一次”;
}
如果(现在<1)
{
x=“现在的时间少于第一次”;
}
我想在数组中存储时间,就像“22:00”一样

然后将字符串更改为时间变量,但只保留小时和分钟

然后将其输入for循环和if语句,以查看哪个更大

php代码可以工作,但我想学习使用Javascript做同样的事情

var date = new Date();
var hour = date.getHours();
var minute = date.getMinutes();
var now = hour + ":" + minute;
var one = "22:30";
var x = "";

if (now > one)
{
 x = "time now is more than time one";
}
if (now < one)
{
 x = "time now is less than time one";
}

非常感谢您的帮助。

PHP可以比较与JS非常相似的字符串。。。实际上,在你比较时间的例子中,时间是完全相同的:

var dateString = "date is: ";
var newDate = new Date();

// Get the month, day, and year.
dateString += (newDate.getMonth() + 1) + "/";
dateString += newDate.getDate() + "/";
dateString += newDate.getFullYear();

document.write(dateString);
<?php
$x = "";
$now = gmdate('H:i');
$one = "22:30";

if ($now > $one) 
{
    $x = "time now is more than time one";
}
elseif ($now < $one)
{
    $x = "time now is less than time one";
}

为什么要投否决票?我不知道如何在javascript中实现php等价物:/I没有否决投票,但可能是因为短时间搜索js时间比较会给出这个问题。你应该通过展示类似的问题来证明你至少做了一些研究,并说明为什么这些答案对你不起作用。thx对于链接,我一直在尝试这样做,但当我运行代码时,我得到了一个错误的结果。thx对于答案,但这不是我要问的:)好的。我想通过这个,我们可以得到日期、月份,一年。但是你到底想要什么,我不明白。你能告诉我吗?那是票,谢谢。