小编20.*_*les的帖子

Angular2 + C#Web Api-服务器端用错误的时间保存日期时间

我正在尝试保存日期时间,但是当webapi收到日期时,它将日期更改为错误的时区。

我的角度应用程序返回:Wed May 22 2019 11:03:35 GMT+0200 但是我的Web Api返回:22/05/2019 09:03:35所以在我的SQL Server数据库中,它被错误地保存了。

我希望它被完全保存 22/05/2019 11:03:35

在我的角度应用程序中,我有这个:

myComponent.component.html

<div class="row">
  <div class="col-4" style="float:left;">
      <div class="form-group">                                
          <div class="input-group">
              <input [ngModel]="newDate | date:'dd/MM/yyyy HH:mm:ss'" 
                  (ngModelChange)="newDate=$event" 
                  name="newDate" 
                  type="datetime"
                  id="new-date"
                  class="form-control">
          </div>
      </div>                    
  </div>
</div>   
<div class="row">
    <div class="col">
        <div class="form-group">                                                                               
            <button type="submit" (click)="onSubmit()" class="btn btn-primary">Submit</button>
        </div>
    </div>            
</div>    
<br>
{{saveDate}}
Run Code Online (Sandbox Code Playgroud)

myComponent.component.ts

import { Component, OnInit, ViewChild, } from '@angular/core';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc asp.net-web-api angular

5
推荐指数
1
解决办法
418
查看次数

标签 统计

angular ×1

asp.net-mvc ×1

asp.net-web-api ×1

c# ×1