-->

Friday 13 February 2009

Kettle : transforming number into hh:mm:ss

Hi all,

Another little code for closing the week.
I'm gathering data coming out of PABX systems. Time is stored with numbers.
Sometimes you just don't want to see 3662 seconds but 01:01:02, with [hh:mm:ss] format.

Be carefull, hh:mm:ss is a string format : you won't be able to do calculations nor apply maths functions on it anymore.

Javascript code (sorry for poor blogspot code formating) :

var time_nb = time.getNumber();

var hh,mm,ss;

var TimeFormat;



ss = time_nb % 60;

mm = time_nb / 60;

hh = mm / 60;

mm = mm % 60;



if(hh<10)(hh="0" + hh);

if(mm<10)(mm="0" + mm);

if(ss<10)(ss="0" + ss);



TimeFormat = hh + ":" + mm + ":" + ss;

No comments: