Sunday, 27 September 2020

Angular - Get Hours, Minutes, meridiem (AM / PM) using moment on matInput type="time"

selected Time from Material TimePicker = '02:18 AM'

.html

<input matInput type="time" [(ngModel)]="inputTime" (ngModelChange)="changeTime()" />


.ts

inputTime: string;


changeTime() {

    const hours = moment(this.inputTime,  'HH').hours();

    const minutes = moment(this.inputTime, 'HH:mm').minutes();

    const meridiem = hours > 12 ? 'PM' : 'AM' ;

    this.inputTime = `${hours}:${minutes}` //Output : 2:18 


   // to get output with leading zero's:

    this.inputTime = `${this. setLeadingZero(hours)}:${this. setLeadingZero(minutes)}` //Output : 02:18

 

    Output:

    console.log(hours); => //Output : 2

    console.log(minutes); => //Output : 18

    console.log(meridiem); => //Output : AM

}

// function to get leading zero's:

setLeadingZero(hour: number) {

  return ('0' + hour).slice(-2)

}

Nodejs - How to switch Nodejs version between projects [Windows]

Step 1: Install Node Version Manager (NVM) Instead of using npm to install and uninstall Node versions for your different projects, you can ...