Answer the question
In order to leave comments, you need to log in
How to calculate date difference in seconds?
The current date, and the date that came from the database:
<script type="text/javascript">
var userDate = new Date();
var currentDateTime = userDate.getFullYear() + "-" + "0" + (userDate.getMonth() + 1) + "-" + userDate.getDate() + " " + userDate.getHours() + ":" + userDate.getMinutes() + ":" + userDate.getSeconds();
var endDate = "<?php echo $end_date;?>"; // это string
</script>
var userDate = new Date();
var currYear = userDate.getFullYear();
var currMonth = "0" + (userDate.getMonth() + 1);
var currDay = userDate.getDate();
var currHours = userDate.getHours();
var currMinutes = userDate.getMinutes();
var currSec = userDate.getSeconds();
var endYear = "<?php echo $year;?>";
var endMonth = "<?php echo $month;?>";
var endDay = "<?php echo $day;?>";
var endHour = "<?php echo $hour;?>";
var endMinute = "<?php echo $minute;?>";
var endSec = "<?php echo $second;?>";
var yearDiff = endYear - currYear;
var monthDiff = endMonth - currMonth;
var dayDiff = endDay - currDay;
var hourDiff = endHour - currHours;
var minDiff = endMinute - currMinutes;
var secDiff = endSec - currSec;
var yearDiffInSec = yearDiff * 365 * 24 * 60 * 60;
var monthDiffInSec = monthDiff * 30 * 24 * 60 * 60;
var dayDiffInSec = dayDiff * 24 * 60 * 60;
var hourDiffInSec = hourDiff * 60 * 60;
var minDiffInSec = minDiff * 60;
var diffInSec = secDiff + minDiffInSec + hourDiffInSec + dayDiffInSec + monthDiffInSec + yearDiffInSec;
Answer the question
In order to leave comments, you need to log in
var differenceSeconds = ((new Date() - new Date("<?php echo $timestamp;?>")) / 1000).toFixed(0);
"0" + (userDate.getMonth() + 1) + "
good luck with 010 and 011 months xD
The date comparison algorithm is always the same.
Convert dates to the same format and compare.
So unix timestamp in hand and go.
Отнять год от года, месяц от месяца, день ото дня, потом создать переменную, равную разница годов*ково секунд в году + разница месяцей* секунд в месяце + разница дней* секунд в 1 дне. Проблема в том, что в месяце не равное колво дней, но задумку ты понял:)
What prevents you from using https://developer.mozilla.org/ru/docs/Web/JavaScri... ?
The result will only need to be divided by 1000.
Well, there is still https://momentjs.com/ .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question