简体   繁体   English

如何将存储在变量中的日期转换为 jquery 中的日期格式?

[英]how to convert the date stored in a variable in to a date formate in jquery?

Following is my jquery code, I want to compare the date pick by user with my gstdate.以下是我的 jquery 代码,我想将用户选择的日期与我的 gstdate 进行比较。

$('#FromDate').on('blur', function() {
  var fromdate = $('#FromDate').val();
  var gstdate = "1-7-2017";
  var gd = new Date('d-m-Y', gstdate);

  if (fromdate <= gst) {
    //do something..
  } else {
    //do something..
  }
});

You need to convert to the fromDate into date variable as you did with gstDate您需要像使用 gstDate 一样将 fromDate 转换为日期变量

$('#FromDate').on('blur', function() {
  var fromdate = new Date("d-m-Y", $('#FromDate').val());
  var gstdate = "1-7-2017";
  var gd = new Date('d-m-Y', gstdate);

  if (fromdate <= gst) {
    //do something..
  } else {
    //do something..
  }
});

You can try momentJs你可以试试momentJs

I hope I've helped you!我希望我帮助了你!

$('#FromDate').on('blur', function() {
  var gstdate = new Date("1-7-2017"); //date object required
  var fromdate = new Date($(this).val());
    console.log(gstdate);
  if (fromdate.getTime() <= gstdate.getTime()) {// getTime() returns the number of milliseconds
    console.log('hello');
  } else {
  console.log('bye');
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM