Over a million developers have joined DZone.

Get Number Of Minutes From Hours

DZone's Guide to

Get Number Of Minutes From Hours

Free Resource
// Last two functions are used to create a correct date object from a UK date string

function FormatMinutesFromHours(time) {
    // Create a new date object so we can play with the time correctly
    var newDate = CreateFullDate("01/01/1900", time);
    // Get the decimal value of minutes
    var decimalTime = newDate.getHours() + (newDate.getMinutes() / 60);
    // Multiply by 60 and round to get the correct number of minutes
    return Math.round(decimalTime * 60);

function CreateFullDate(dateStr, TimeStr) {
    // Convert into a uk date object
    var formatUK = FormatUkDate(dateStr);
    // Next take the uk date object and convert into an american date string!
    var formatUS = formatUK.format("MM/dd/yyyy");
    // Create a new date object from the american date and time
    return new Date(formatUS + " " + TimeStr);

function FormatUkDate(dateStr) { 
    dateStr = dateStr.split("/");
    return new Date(dateStr[2], dateStr[1] - 1, dateStr[0]);

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}