javascript - 基于日期的页面重定向以及如何将日期转换为字符串
问题描述
我正在使用结束日期和当前日期进行页面重定向,想根据日期重定向页面,我确实喜欢这个
问题:重定向不起作用
<script type="text/javascript">
function callFunc()
{
var endDate = new Date(07-05-2019);
var curDate = new Date();
if (new Date(endDate) > new Date(curDate))
{
window.location.replace('/AppName/page/page');
} else {
return "";
}
}
</script>
解决方案
function callFunc() {
// Has to be a valid string to get parsed.
var endDate = new Date( '2019-05-07' );
var curDate = new Date();
// No reason to create a new Date() from something that is already a Date object.
// Use getTime() to get an integer representing the datetime.
// Compare those instead of the Date objects to avoid issues.
if ( endDate.getTime() > curDate.getTime() ) {
console.log( 'change location' );
} else {
console.log( 'do nothing' );
}
}
callFunc();
推荐阅读
- arrays - 需要 json_encode 返回排序后的数组
- python - 如何在 python 中生成 *.dict 和 *.idx 文件?
- javascript - 字符串如何存储在内存中的js
- javascript - 初始化 Express SQL Server 连接导致无限页面加载
- postgresql - “System.NullReferenceException”在查询数据库 EntityFrameworkCore 时使用 EF.Property
- r - R中qq绘图中的线条样式
- google-apps-script - Google 应用脚本 ScriptApp.getService().getUrl() 总是返回错误的 URL
- python - 在 pip install python package 期间正确编码
- python - 如何在python中获取范围之间的值
- python - 如何在 django 中只显示一些对象?