0
I’m trying to put double digits on getMonth
, but it’s going wrong. What I’m doing wrong?
var data = new Date();
var dia = ("0" + data.getDate()).slice(-2);
var mes = ("0" + (data.getMonth() + 1)).slice(-2);
var ano4 = data.getFullYear();
var hora = ("0" + data.getHours()).slice(-2);
var min = ("0" + data.getMinutes()).slice(-2);
var str_data = dia + '/' + (mes + 1) + '/' + ano4;
var str_hora = hora + ':' + min;
console.log(str_data + " " + str_hora);
I didn’t get that
(mes + 1)
... is concatenating the month + the number 1. Maybe it should just bemes
, thus:var str_data = dia + '/' + mes + '/' + ano4;
– Sam
@Sam Err that same...rsrs Thank you.
– Tiago
Maybe your code can be more effective using https://momentjs.com/
– Raphael Ornellas