samedi 25 avril 2015

How to find today's date in DateTimePicker JavaScript?


I'm using the following javascript: http://ift.tt/1MosCse , and I want to achieve simple effect - when User selects today's day, it should show him only hours available from now until the end of the day, the previous time should be disabled. But when he choses any other day in the future - then the whole time should be available. I wrote the following function in JS:

<script>
var today = new Date();
var dd = today.getDate();
alert(dd);
           var logic = function( currentDateTime ){
  if( currentDateTime.getDay()==dd ){
    this.setOptions({
      formatTime:'g:i A', 
format: 'd/m/Y h:i A',
  minDate:'+1970/01/02',//today
  minTime: //I don't know yet how to implement the current time
    });
  }else
    this.setOptions({
     formatTime:'g:i A', 
format: 'd/m/Y h:i A',
  minDate:'+1970/01/02'//today
    });
};


                jQuery('#datetimepicker').datetimepicker({
                onChangeDateTime:logic,
                onShow:logic
                });

</script>

The problem is that that line:

currentDateTime.getDay()==dd

doesn't work, because in my case dd equals todays day of the month (e.g. 25), and currentDateTime.getDay() checks current day of the week (e.g. for saturday it's 6). Is there anyone who could help me with that issue? I know there are some other available solutions (other datetime pickers), but I cannot find any other that is as simple and elegant as this. Thanks!


Aucun commentaire:

Enregistrer un commentaire