Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

373
Visualizações
How to display current date and time using ionic

Here I am trying to develop a mobile application using an ionic framework. I want to set the current time and date in my application. But it didn't work. Can anyone help me to solve this problem? Here is my code.

HTML code

<ion-datetime
#dateTime
displayFormat="MMM DD, YYYY HH:mm"
formControlName="myDate"></ion-datetime>

ts. code

export class App{
@ViewChild('dateTime') dateTime;

 form: FormGroup
 myDate: FormControl = new FormControl('', Validators.required)

 constructor(private fb: FormBuilder) {}

 ngOnInit() {
this.form = this.fb.group({
  myDate: this.myDate
});

setTimeout(_ => {
  this.dateTime.setValue(new Date().toISOString());
  });
}
 }
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

have you tried to use [value] property instead of ViewChild? Try to do this:

<ion-content>
  <ion-datetime [value]="dateTime" displayFormat="MMM DD, YYYY HH:mm" ></ion-datetime>
</ion-content>

and in your ts file:

  dateTime;

  constructor() { }

  ngOnInit() {
    setTimeout(() => {
      this.dateTime = new Date().toISOString();
    });
  }

this worked out for me!

about 4 years ago · Juan Pablo Isaza Relatório

0

I have tried another code found from google and it worked perfectly. Here is the code;

HTML

<ion-item>
<ion-datetime min="2021" max={{currentDate}} displayFormat= "DD/MM/YYYY  h:mm A" 
  [(ngModel)]="chosenDate"></ion-datetime>
</ion-item>
<p> Current date is {{currentDate}}</p>
<p> Chosen date is {{chosenDate}}</p>

ts.code

export class App implements OnInit {
 public currentDate: String;
 public chosenDate: String;
 constructor(public navCtrl: NavController,private platform:Platform) {
   this.currentDate = (new Date()).toISOString();
   this.chosenDate = this.currentDate;
  });
 }
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda