Decimal To Time Formatting

Beberapa menit googling ga nemu script untuk formatting Decimal to Time. contoh input: 8.5, output: 8:30. hal ini dimaksudkan untuk formatting time untuk membuat modul timesheet di aplikasi. berikut script sederhana yang terpaksa dibikin sendiri, kira2 ada ide bwt lebih menyederhanakan?

function ConvertDecimalToTime(decimal) {
var stringValue = String(decimal);
var hours;
var minutes;
if (stringValue.indexOf(",") != -1) {
minutes = SplitMinutes(stringValue, ",");
hours = SplitHours(stringValue, ",");
}
else if (stringValue.indexOf(".") != -1) {
minutes = SplitMinutes(stringValue, ".");
hours = SplitHours(stringValue, ".");
}
else {
return stringValue + ":00";
}
return hours + ":" + minutes;
}

function SplitMinutes(stringValue, separator) {
var result = stringValue.substring(stringValue.indexOf(separator) + 1, stringValue.length);
result = "0." + result;
result = parseFloat(result) * 60;
return String(result);
}

function SplitHours(stringValue, separator) {
return stringValue.substring(0, stringValue.indexOf(separator));
}
Be Sociable, Share!

Leave a Reply

Your email address will not be published. Required fields are marked *

*


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

[+] kaskus emoticons nartzco