How to fix date to retrieve minutes/hours with zeros ?
e.g. it’s 05:09 AM >
trace(_date.getHours()+":"+_date.getMinutes()); //5:9
but i want 05:09 instead of 5:9 – so how to add zeros ??
var _date = new Date();
...
_min = _date.getMinutes();
//fix date:
var _str:String = _min.toFixed(1);
_min = Number(_str);
trace(_date.getHours()+":"+_date.getMinutes());
= 5:9 …. -_-
what’s wrong ?
You can format it with something like:
minutes_txt:String = _date.getMinutes() < 10 ? “0” + _date.getMinutes() : _date.getMinutes();
which will pad a zero if the minutes is less than 10, and then just trace that instead of only _date.getMinutes