在js中如何比较两个时间字符串的大小.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>

<body>
<script>
function CompareDate(d1,d2)
{
return ((new Date(d1.replace(/-/g,"/"))) > (new Date(d2.replace(/-/g,"/"))));
}

var current_time = "2007-2-2 7:30";
var stop_time = "2007-1-31 8:30";
alert(CompareDate(current_time,stop_time));

</script>
</body>
</html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
</head>
<body>
<script>
function CompareDate(d1,d2)
{
return ((new Date(d1.replace(/-/g,"/"))) > (new Date(d2.replace(/-/g,"/"))));
}
var current_time = "2007-2-2 7:30";
var stop_time = "2007-1-31 8:30";
alert(CompareDate(current_time,stop_time));
</script>
</body>
</html>
本文介绍了一种使用JavaScript来比较两个时间字符串的方法。通过将时间字符串转换为Date对象并进行比较,可以有效地判断一个时间是否早于另一个时间。这种方法在实际应用中非常有用,例如在网页上实现时间限制的功能。


1147

被折叠的 条评论
为什么被折叠?



