У меня есть текущий скрипт. var date 2 необходимо автоматически захватить текущую дату, а затем выполнить расчет. Я пробовал много вещей, не повезло, пожалуйста, помогите.как вставить текущую дату в html-скрипт
<script>
// Here are the two dates to compare
var date1 = '2015-09-08';
var date2 = '2015-12-13';
// First we split the values to arrays date1[0] is the year, [1] the month and [2] the day
date1 = date1.split('-');
date2 = date2.split('-');
// Now we convert the array to a Date object, which has several helpful methods
date1 = new Date(date1[0], date1[1], date1[2]);
date2 = new Date(date2[0], date2[1], date2[2]);
// We use the getTime() method and get the unixtime (in milliseconds, but we want seconds, therefore we divide it through 1000)
date1_unixtime = parseInt(date1.getTime()/1000);
date2_unixtime = parseInt(date2.getTime()/1000);
// This is the calculated difference in seconds
var timeDifference = date2_unixtime - date1_unixtime;
// in Hours
var timeDifferenceInHours = timeDifference/60/60;
// in weeks :)
var timeDifferenceInWeeks = timeDifferenceInHours/24/7;
document.write(Math.ceil(timeDifferenceInWeeks));
</script>
Не определяйте 'уаг date2 = '2015-12-13', 'следовательно, разделение операция не будет there..Just' вар date2 = новый Date(); 'Попробуйте это : https://jsfiddle.net/09aoz9u1/ – Rayon
Если я использую вашу идею, расчет не произойдет. – aumandg
Вы проверили скрипку? – Rayon