Date format coming wrong

2020-05-10 06:18发布

vr_date :Date

alert(this.vr_date ) // Result Shows Thu Feb 07 2019 00:00:00 GMT+0400

var json = JSON.stringify(this.vr_date);

alert(json); // Result Shows 2019-02-06T20:00:00.000Z see the date goes wrong

the output day shows 06 instead of 07

my html

<input matInput 
   [(ngModel)]="vr_date" 
   name="vr_date"  
   [matDatepicker]="myDatepicker" 
   matInput 
   placeholder="Vr Date" 
   [readonly]="true" >
<mat-datepicker-toggle matSuffix [for]="myDatepicker" ></mat-datepicker-toggle>
<mat-datepicker #myDatepicker></mat-datepicker>

2条回答
家丑人穷心不美
2楼-- · 2020-05-10 06:36

i sloved using this this.vr_date.setHours(this.vr_date.getHours() - this.vr_date.getTimezoneOffset() / 60);

查看更多
▲ chillily
3楼-- · 2020-05-10 06:45

Looks like the timezone is different. In the first alert, you get day 07, time 00:00 with GMT +4. In the second alert, you get the definition of the date object, (stored in GMT format). Now, if you substract those +4 hours from the first alert, you get the second alert: day: 06, time 20:00.

查看更多
登录 后发表回答