jquery - 减去今天结束日期的日期,如果剩余日期少于6个月则给出消息

时间:2015-11-06 07:52:40

标签: php jquery date laravel

我正在laravel

处理表单验证,护照签发日期和护照结束日期
 <div class="control-group">
    {!! Form::label('passportIssuedate', 'Passport Issue Date') !!}
    <div class="controls">
        {!! Form::date('passportIssuedate', null, 
     array('id'=>'issuedate',                   
    'class'=>'span8 form-control')) !!}
    </div>
    <!-- /controls -->
    </div>


     <div class="control-group">
    {!! Form::label('passportExpirydate', 'Passport Expiry Date') !!}
    <div class="controls">
        {!! Form::date('passportExpirydate', 
    null, array('id'=>'expdate', 'class'=>'span8 form-control')) !!}
    </div>

    </div>
我能这样做吗?

$(document).ready(function(){

var todaydate = $.now();
var enddate = getElementbyID('#expdate').value;
var result = enddate - todaydate;

 if(result < 6 months){
   alert("the expiry date duration should be more than six months");
  }

});

任何帮助,提前高度赞赏。 thnx很多。

3 个答案:

答案 0 :(得分:1)

假设“enddate”和“todaydate”是“Date”对象的实例,你可以这样做

diffInMs = enddate.getTime() - todaydate.getTime();
diffInDays = diffInMs /1000/ 60 / 60 / 24;

答案 1 :(得分:1)

试试这个:

    ' This function creates a bitmap of a solid color.
    Dim srcImg As Bitmap = ImageUtil.CreateSolidcolorBitmap(New Size(256, 256), Color.Red)
    Dim modImg As Image = srcImg.ChangeColor(Color.Red, Color.Blue)

    PictureBox1.BackgroundImage = srcImg 
    PictureBox2.BackgroundImage = modImg 

答案 2 :(得分:0)

在moment.js我完成了我的任务

<script src="{{ URL::asset('js/moment.js')  }}"></script>
<script type="text/javascript">

   $(document).ready(function(){

        $('#lastdate').blur(function(){
            mydate();
        });        

    });

   function mydate(){
        var duration = moment.duration(6, 'M').humanize();
        var lastdate = $("#lastdate").val();
        var today = moment().format('L');
        var ldate = moment(lastdate).diff(moment(today));
        var Result = moment.duration(ldate).humanize();
        //alert(Result);
        if(Result <= duration){
            var itsays= "some text message";
            $(".classnametobeshowninview").html(itsays);
        }else{
            $(".classnametobeshowninview").html("");
        }
   }

</script>