简体   繁体   English

更改 Kendo DatePicker 或 Jquery 完整日期字符串格式的日期值

[英]Changing a date value of Kendo DatePicker or Jquery full date string format

I currently have a Kendo DatePicker in my grid.我目前在我的网格中有一个 Kendo DatePicker。 The format I use is MM/yyyy.我使用的格式是 MM/yyyy。 I don't need to select a Day.我不需要选择一天。 But in DB, when I select dates and hit the save changes button, the DatePicker chooses a Day as "1", and the DB inserts that value.但是在 DB 中,当我选择日期并点击保存更改按钮时,DatePicker 将日期选择为“1”,并且 DB 会插入该值。 So For example, if I select 9/2020 from the UI and submit, in DB, the value will be 2020-09-01.例如,如果我从 UI 中选择 9/2020 并提交,在 DB 中,该值将为 2020-09-01。

So now the problem is, I have another Date Picker search filter outside of the grid.所以现在的问题是,我在网格之外还有另一个日期选择器搜索过滤器。 When I select a date, for example, 9/2020, it searches for "2020-09-[Today's Day]" in stead of "2020-09-01".当我选择一个日期时,例如 9/2020,它会搜索“2020-09-[Today's Day]”而不是“2020-09-01”。 So it will just return nothing even if I just inserted 09/20 data.因此,即使我只是插入了 09/20 数据,它也不会返回任何内容。

Date Picker that I'm using as a search feature:我用作搜索功能的日期选择器:

    $('#searchBoxDate').kendoDatePicker({
        start: "year",
        depth: "year",
        min: new Date(2000, 01, 01),
        format: "{0:MM/yyyy}"
    });

My question is --我的问题是——

  1. Is there a way to make #searchBoxDate automatically select a Day as "1" when I select Year and Month?当我选择年和月时,有没有办法让 #searchBoxDate 自动选择一天为“1”?

OR或者

  1. Is there a way to change the Day "18" to "1" in a full string format?有没有办法以完整的字符串格式将“18”日更改为“1”? Sun Oct 18 2020 01:39:28 GMT-0400 (Eastern Daylight Time) 2020 年 10 月 18 日,星期日 01:39:28 GMT-0400(东部夏令时间)

Add a change function to the onChange event to always correct the date to the first day of the month:向 onChange 事件添加更改函数以始终将日期更正为该月的第一天:

change: function() {
      var value = this.value();
      var days = value.getDate();
      var d = new Date();
      d = value;
      d.setDate(d.getDate()-days+1);
        console.log(d); 
    }

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

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