datetimeoffset未正确回发 - MomentJS

时间:2017-05-27 16:24:47

标签: c# jquery html knockout.js momentjs

技术

KnockoutJS,Knockout Mapping Plugin,MomentJS,SQL Server,C#Web服务

问题

通过模态弹出窗口添加时间输入,将开始时间设置为上午7:30到下午4:30。无论用户所在的时区,我都希望这种情况始终如此。这似乎工作正常,但是当我通过ajax保存结果时,它将更改为11:30和20:30。它不包括我认为是关注但需要澄清的时区。我现在只在本地运行,所以在EST上。

思想

我希望数据库显示7:30 -4:00或者我的想法不正确?我还需要它以正确的方式加载回来当前它也可以,但我担心如果芝加哥时间我的服务器/数据库和EST中的用户它将无法正常加载。

代码

新时间录入

self.NewTimeEntry = function () {
    var today = new Date();

    console.log(moment(moment().format('MM/DD/YYYY')).add(7, 'h').add(30, 'm'));
    console.log(moment(moment().format('MM/DD/YYYY')).add(16, 'h').add(30, 'm'));

    var newEntry = {
        ID: -1,
        EmployeeID: -1,
        WorkorderID: self.WorkorderID(),
        JobDate: today,
        Description: '',
        LunchBreak: 0.5,
        StartedOn: moment(moment().format('MM/DD/YYYY')).add(7, 'h').add(30, 'm'),
        FinishedOn: moment(moment().format('MM/DD/YYYY')).add(16, 'h').add(30, 'm')
    };
    self.EmployeeHoursModal.unshift(new EmployeeHour(self, newEntry));

    ScrollToTop('#' + self.WorkorderHoursModalID() + ' .modal-body')
}

控制台结果 enter image description here

员工小时视图模型

function EmployeeHour(parent, dto) {
var self = this;
dto = dto || {};
var mapping = { 'ignore': ['__type', '_type', 'type'] }

ko.mapping.fromJS(dto, mapping, self);

self.LunchBreakOptions = ko.observableArray([
    new RadioButton('No Lunch', 0, self.LunchBreak, function () { return self.LunchBreak() == 0; }),
    new RadioButton('15', .25, self.LunchBreak, function () { return self.LunchBreak() == .25; }),
    new RadioButton('30', .50, self.LunchBreak, function () { return self.LunchBreak() == .50; }),
    new RadioButton('45', .75, self.LunchBreak, function () { return self.LunchBreak() == .75; }),
    new RadioButton('1 Hour', 1, self.LunchBreak, function () { return self.LunchBreak() == 1; })
]);

self.StartedOn = ko.observable(moment(dto.StartedOn));
self.FinishedOn = ko.observable(moment(dto.FinishedOn));

self.CalculateTotal = ko.computed(function () {
    if (self.StartedOn() != null && self.FinishedOn() != null) {
        var endTime = moment.utc(self.FinishedOn()).subtract((60 * self.LunchBreak()), 'm').toDate();
        var totalTime = moment.utc(moment.utc(endTime, "DD/MM/YYYY HH:mm:ss").diff(moment.utc(self.StartedOn(), "DD/MM/YYYY HH:mm:ss"))); //.format("HH:mm");
        if (parseInt(totalTime.format('HH')) == 1) {
            return parseInt(totalTime.format('HH')) + ' Hour' + ((parseInt(totalTime.format('mm')) > 0) ? ' and ' + totalTime.format('mm') + ' minutes' : '');
        } else {
            return parseInt(totalTime.format('HH')) + ' Hours' + ((parseInt(totalTime.format('mm')) > 0) ? ' and ' + totalTime.format('mm') + ' minutes' : '');
        }
    } else {
        return 'None';
    }
});
}

模态弹出 enter image description here

客户端保存代码

self.SaveTimeEntries = function () {
    IsSaving('time entries');

    for (var idx = 0; idx < self.EmployeeHoursModal().length; ++idx) {
        var hourDTO = {
            dto: ko.toJS(self.EmployeeHoursModal()[idx])
        };

        PostDTO('/WorkorderService.asmx/SaveJobHour', hourDTO, function (obj) {
            self.EmployeeHoursModal()[idx].ID(obj.ID);
        });
    }

    SavedSuccessfully();
}

服务器保存代码 enter image description here

0 个答案:

没有答案