0
I created a function that receives an account, I need to check if a property conta.venc_token
is longer than today’s date, if it is, return true
(because it is an invalid token), otherwise return false
.
I tried that way:
verificaVenceuConta(conta):boolean{
var data = conta.venc_token
console.log(data);
console.log(new Date())
if(data > new Date()){
console.log("entrou no if")
return true
}else{
console.log("entrou no false")
return false
}
}
But the format that returns from my backend is very different from the format that javascript generates the current date.
Us console.log
I have:
Format of my backend:
10/04/2019 18:27:38
Format that javascript generates:
Wed Apr 10 2019 14:28:55 GMT-0300 (Horário Padrão de Brasília)
I would like to know a way to compare. This way I found can correctly compare dates and times? By the tests I’ve done always returns in else
(false).
If
console.log(data);
prints10/04/2019 18:27:38
, is probably a string (which you should convert toDate
) - check outtypeof(data)
just to be sure. Because when printing aDate
, it is always shown in this format "Wed Apr 10 etc...". Another detail is to know if 18:27 is in the same time zone as the frontend, otherwise there is no way to make the conversion reliably.– hkotsubo
Yeah, it’s kind of string
– veroneseComS