无法更新属性并更改 Breeze 中其他属性的时区

can't update attribute and change the TimeZone for other attribute in Breeze

在激活我的编辑视图页面时,我试图使用外键从不同的表中获取实体,我得到了,但我认为这不是获取和更新实体的正确方法,这不会保存更新的属性 "modification_date" 我面临的另一个问题是时间问题,因为我有一个属性 "startDate" 是日期时间类型,所以当我将我的应用程序托管到某个 VM 时,它会显示时间比原始值多 +5:30,因为数据库在 GMT +00:00 中存储该值。我怎么解决这个问题? 我的问题是:

  1. Why "modification_date" is not saving current date, whenever entity is updated.
 <input data-bind="value: modificationDate = $root.md, visible: false"
>

Javascript

vm.md = ko.dependentObservable(function () {
        var y = new Date();// should assign current to modification date but its not persisting the changes to database.
        return y;
        }, vm);
  1. How can I show the correct time which is in GMT +00:00 to client side when my current is GMT +5:30. While editing and fetching the data from SqlServer.

  2. Please comment how we use the navigation key to access the other table as what I am doing is getting a 'Job' observable and in that different attributes are there and another table is 'job_Schedule', so how should I access the property startDate which is under 'job_Schedule' table. As currently I am accessing is like job_Schedule._latestValue[0].startDate which is probably not the right way to fetch the entity.

这是我的一段代码:

 <div data-bind="with: job">
<label>Start Date :</label>
                        <input data-bind="kendoDateTimePicker: $root.temp3" />
                        <input data-bind="value: job_Schedule._latestValue[0].startDate = $root.tempSD1, visible: false" />
     <input data-bind="value: modificationDate = $root.md, visible: false" >
//I kept visible: false because modified date should be updated automatically
// some more attributes................
</div> 

Javascript代码

    vm.md = ko.dependentObservable(function () {
    var y = new Date();// should assign current to modification date but its not persisting the changes to database.
    return y;
    }, vm);

vm.tempSD = ko.dependentObservable(function () {
    var y = ko.unwrap(this.tempx());// tempx containing the current value of startDate
    if (y === null || y === '""') { y = new Date(); }
    y = new Date(y);
    var utc = y.getTime() + (y.getTimezoneOffset() * 60000);
    temp3(new Date(utc));
    return new Date(utc);
}, vm);

vm.tempSD1 = ko.computed(function () {
    var y = vm.temp3();
    if (y === null || y === '""') {y = new Date();}
    y = new Date(y);
    var utc = y.getTime() - (y.getTimezoneOffset() * 60000);
    return new Date(utc);
},vm);

日期操纵对于每项技术中的每个人来说都是一个长期存在的挑战。

时区操作特别棘手,尤其是当客户端和服务器处于不同时区时。

当您可以确保所有日期都已创建并存储在 UTC 中时,这可能不是什么问题。我认为您不想完全依赖对 new Date().

的调用

我建议查看 momentjs date/time library

我不知道如何解决您关于导航到相关实体的问题,因为您没有提供有关所涉及的实体类型或其关系的任何信息。这是一个单独的问题吗?或者你的导航 属性 和你的日期问题有联系吗?