Подтвердить что ты не робот

Дата проверки более 30 дней с сегодняшнего дня

Я использую jQuery datepicker и пытаюсь выяснить разницу между сегодняшней датой и выбранной датой, но получаю проблемы... а не проблемы... Я не смог найти это идеально...

Я попытался сделать это on 'onSelect event datepicker'

Вопрос: Как проверить, была ли выбранная дата с использованием jQuery Datepicjer более 30 дней с сегодняшней даты?

Любая помощь будет оценена....!! note: не хочу использовать какие-либо библиотеки, мне нужно решить это, используя только jQuery.

4b9b3361

Ответ 1

Получите отметку времени в течение 30 дней:

var timestamp = new Date().getTime() + (30 * 24 * 60 * 60 * 1000)
//                                      day hour  min  sec  msec

Сравните эту метку времени с меткой времени для выбранной даты.

if (timestamp > selectedTimestamp) {
    // The selected time is less than 30 days from now
}
else if (timestamp < selectedTimestamp) {
    // The selected time is more than 30 days from now
}
else {
    // -Exact- same timestamps.
}

Ответ 2

Я создал для вас один образец.

 <!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>jQuery UI Datepicker - Default functionality</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
  <script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css" />
  <script>
  $(function() {
    $( "#datepicker" ).datepicker();
  });
  </script>
</head>
<body>

Date: <input type="text" id="thedate"/>
<div id="checkDate">Check Date</div>
</body>
</html>

и Js

$('#thedate').datepicker();

$('#checkDate').bind('click', function() {
  var selectedDate = $('#thedate').datepicker('getDate');
  var today = new Date(); 
  var targetDate= new Date();
  targetDate.setDate(today.getDate()+ 30);
  targetDate.setHours(0);
  targetDate.setMinutes(0);
  targetDate.setSeconds(0);

  if (Date.parse(targetDate ) >Date.parse(selectedDate)) {
    alert('Within Date limits');
  } else {
    alert('not Within Date limits');
  }
});

Вы можете проверить этот код онлайн Здесь

Ответ 3

Попробуйте следующее:

$('input').datepicker({
    onSelect: function()
    {
        var date = $(this).datepicker('getDate');
        var today = new Date();
        if((new Date(today.getFullYear(), today.getMonth(), today.getDate()+30))>date)
        {
             //Do somthing here..
        }

    },
});

demo: http://jsfiddle.net/jeY7S/