Ionic timepicker 限制结果

我正在使用ionic datetime,我只想从中得到,hours,minutes,seconds但我得到的结果是这样的2020-10-05T00:00:27.634+07:00,我只需要从这个结果中得到00:00:27。


我的问题是如何将结果限制为我喜欢的版本?


代码

<ion-datetime display-format="HH:mm:ss" picker-format="HH:mm:ss" formControlName="quiz_time"></ion-datetime>

请注意,此标记<ion-datetime>是 ionic default,我没有在组件中添加任何其他内容来运行它,因此没有什么可以与您分享的,但我显然需要的是在我的组件中添加一些功能以限制结果这个输入,这就是我寻求帮助的原因。


component


发送数据到后端


quizCreate() {

    const sems = this.quizData.value;

    this.quizService.quizCreate(

        sems.quiz_time, // my input (2020-10-05T00:00:27.634+07:00)

    ).subscribe(

      (data: any) => {

        console.log(data.message);

      },

      error => {

        //

      },

      () => {

        //

      }

    );

}

任何想法?


芜湖不芜
浏览 100回答 1
1回答

素胚勾勒不出你

解决了这是我解决问题的最终代码quizCreate() {&nbsp; &nbsp; const sems = this.quizData.value;&nbsp; &nbsp; // convert coming time&nbsp; &nbsp; const d = new Date(Date.parse(sems.quiz_time)); // my input (2020-10-05T00:00:27.634+07:00)&nbsp; &nbsp; // add second digits&nbsp; &nbsp; const hours = ("0" + d.getHours()).slice(-2);&nbsp; &nbsp; const minutes = ("0" + d.getMinutes()).slice(-2);&nbsp; &nbsp; const seconds = ("0" + d.getSeconds()).slice(-2);&nbsp; &nbsp; // join times&nbsp; &nbsp; const quizTime = hours + ":" + minutes + ":" + seconds;&nbsp; &nbsp; this.quizService.quizCreate(&nbsp; &nbsp; &nbsp; &nbsp; sems.quiz_time = quizTime, // send joined time (00:00:27)&nbsp; &nbsp; ).subscribe(&nbsp; &nbsp; &nbsp; (data: any) => {&nbsp; &nbsp; &nbsp; &nbsp; console.log(data.message);&nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; error => {&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; () => {&nbsp; &nbsp; &nbsp; &nbsp; //&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; );}希望它可以帮助别人。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript