SteffPoint
SteffPoint

Reputation: 559

as3 - displaying "0" when seconds are under "10"

I'm actually displaying the current time (including seconds) on an application I'm working on (Adobe Flash with AS3). I've made it to be able to display the date, hours, minutes and seconds, however, I noticed, that my seconds under the value "10" are displayed without any zero. Example: 8:48:5 (zero missing). I hope someone of you can help me. Thanks in advance :)

var my_date:Date;

var my_timer:Timer=new Timer(1000);
my_timer.addEventListener(TimerEvent.TIMER, onTimer);
my_timer.start();

function onTimer(e:TimerEvent):void {
my_date = new Date();
tag.text = "" +my_date.date+"."+my_date.month+"."+my_date.fullYear+"  "+my_date.hours+":"+my_date.minutes+":"+my_date.seconds;  
}

Upvotes: 0

Views: 52

Answers (1)

Sergio Ivanuzzo
Sergio Ivanuzzo

Reputation: 1922

According to comment of user @akmozo you can use this:

(my_date.seconds < 10 ? "0" + my_date.seconds : my_date.seconds);

Upvotes: 2

Related Questions