下面是我的javascript文件,其中包含这样的
//custom.js
var setting = {
lastDate: '06/01/2016 09:18:00', //Date format: month/day/year hours:minutes:seconds
timeZone: GMT +8, //GMT +10 or -5
style:{
colorStart:'#3CEAEE', //Background color start. Any #hex color, only 6 characters
colorEnd:'#0d4266', //Background color end. Any #hex color, only 6 characters
bgStyle:'circularMiddleCenter' //Background style
}
};
所以在我的index.html中。如何从js文件中获取lastDate值并进行比较?
我的index.html有一个始终处于禁用模式的按钮,当lastDate到达时,概念使用当前日期 - lastDate。然后按钮将被启用并执行操作。
<button>Let's Go</button>
有什么建议吗?
答案 0 :(得分:0)
您应该使用new Date()
来获取实现目的的当前时间
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script>
//custom.js
var setting = {
lastDate: '5/30/2016 09:18:00', //Date format: month/day/year hours:minutes:seconds
timeZone: "GMT +8", //GMT +10 or -5
style: {
colorStart: '#3CEAEE', //Background color start. Any #hex color, only 6 characters
colorEnd: '#0d4266', //Background color end. Any #hex color, only 6 characters
bgStyle: 'circularMiddleCenter' //Background style
}
};
$(document).ready(function() {
console.log((new Date().getTime() / 1000));
if ((new Date(setting.lastDate).getTime() / 1000) <= (new Date().getTime() / 1000)) {
alert("reach");
}
});
</script>