如何将 Ionic 日期选择器中的日期转换为 Ionic 4 中的 'Y-m-d H:i:s'
How to convert the date in Ionic date picker to 'Y-m-d H:i:s' In Ionic 4
我在我的 Ionic 4 应用程序中工作,我的 Ionic 4 应用程序中有日期时间选择器,我正在发送该日期和时间,但日期和时间格式应该是 Y-m-d H:i:s
。
这是我的html:
<ion-datetime formControlName="startchallenge" displayFormat="DD-MM-YY HH:mm:ss" pickerFormat="DD-MM-YY HH:mm:ss" placeholder="Select Date" [min]="minDate" [max]="maxDate"></ion-datetime>
我在 ts 文件中获取这个日期和时间,然后我必须转换这个日期和时间并以 Y-m-d H:i:s
.[=17 格式发送=]
这是我的 ts:
datetime: any;
this.datetime = this.acceptchallengeform.value.startchallenge
我想按以下格式发送此日期和时间:Y-m-d H:i:s
。现在发送为 2019-03-15T06:11:52Z
.
非常感谢任何帮助。
将此添加到您的 ts 文件中:
let workOutDate=this.acceptchallengeform.value.startchallenge;
workOutDate=workOutDate.replace('T',' ');
workOutDate=workOutDate.replace('Z','');
然后发送最终日期,因为您是从日期选择器 2019-03-15T06:11:52Z
获取此日期格式,更改后将变为 2019-03-15 06:11:52
。
所以这解决了我的问题,因为我将这个日期发送到付款服务并且它正在接受这个日期 2019-03-15 06:11:52
。
我在我的 Ionic 4 应用程序中工作,我的 Ionic 4 应用程序中有日期时间选择器,我正在发送该日期和时间,但日期和时间格式应该是 Y-m-d H:i:s
。
这是我的html:
<ion-datetime formControlName="startchallenge" displayFormat="DD-MM-YY HH:mm:ss" pickerFormat="DD-MM-YY HH:mm:ss" placeholder="Select Date" [min]="minDate" [max]="maxDate"></ion-datetime>
我在 ts 文件中获取这个日期和时间,然后我必须转换这个日期和时间并以 Y-m-d H:i:s
.[=17 格式发送=]
这是我的 ts:
datetime: any;
this.datetime = this.acceptchallengeform.value.startchallenge
我想按以下格式发送此日期和时间:Y-m-d H:i:s
。现在发送为 2019-03-15T06:11:52Z
.
非常感谢任何帮助。
将此添加到您的 ts 文件中:
let workOutDate=this.acceptchallengeform.value.startchallenge;
workOutDate=workOutDate.replace('T',' ');
workOutDate=workOutDate.replace('Z','');
然后发送最终日期,因为您是从日期选择器 2019-03-15T06:11:52Z
获取此日期格式,更改后将变为 2019-03-15 06:11:52
。
所以这解决了我的问题,因为我将这个日期发送到付款服务并且它正在接受这个日期 2019-03-15 06:11:52
。