Home > Blockchain >  How to display current time using ng-forms
How to display current time using ng-forms

Time:01-18

Display current time using ng-forms

<input
  type="time"
  
  path="time"
  formControlName="time"
  [ngClass]="{'is-invalid': submitted && f.time.errors}"
/>

CodePudding user response:

Try This one too

You can use the Angular2 Date Pipe to display a JavaScript Date object. Check the docs (linked) for the correct formatting that you are looking for.

Solution 1 :

@Component({
  selector: 'date-pipe',
  template: `<div>
    <p>Today is {{today | date}}</p>
    <p>Or if you prefer, {{today | date:'fullDate'}}</p>
    <p>The time is {{today | date:'jmZ'}}</p>
    <p>Finally the date and time is {{today | date:'short'}}</p>
  </div>`
})
export class DatePipeComponent {
  today: number = Date.now();
}

Solution 2 :

{{date  | date:'yyyy-MM-dd'}}

Solution 3 :

import { DatePipe } from '@angular/common'
...
constructor(public datepipe: DatePipe){}
...
myFunction(){
 this.date=new Date();
 let latest_date =this.datepipe.transform(this.date, 'yyyy-MM-dd');
}
  •  Tags:  
  • Related