This question already has answers here:
Convert seconds to HH-MM-SS with JavaScript?
(38 answers)
Javascript seconds to minutes and seconds
(30 answers)
Closed 23 days ago.
I found a way to convert to hours and munites, how can I convert to minutes and seconds?
function time_convert(num)
{
var hours = Math.floor(num / 60);
var minutes = num % 60;
return hours + ":" + minutes;
}
console.log(time_convert(71));
console.log(time_convert(450));
console.log(time_convert(1441));
Related
This question already has answers here:
Converting milliseconds to minutes and seconds with Javascript
(14 answers)
converting milliseconds to nearest minute in javascript
(2 answers)
JavaScript - Get minutes between two dates
(12 answers)
Closed 3 years ago.
I have to get the difference of present timings(eg:1579770577465) and some planned time(eg:1579768500000) and I need to convert into minutes. How I can do it?
1579770577465 - 1579768500000 = 2077465
I want 2077465 in minutes.
Here you go:
var deltaMs = msData2 - msData1;
var totalSeconds = parseInt(Math.floor(deltaMs / 1000), 10);
var totalMinutes = parseInt(Math.floor(totalSeconds / 60), 10);
var totalHours = parseInt(Math.floor(totalMinutes / 60), 10);
var days = parseInt(Math.floor(totalHours / 24), 10);
var seconds = parseInt(totalSeconds % 60, 10);
var minutes = parseInt(totalMinutes % 60, 10);
var hours = parseInt(totalHours % 24, 10);
This question already has answers here:
how to convert minutes to hours using moment.js
(2 answers)
Closed 3 years ago.
I am using moment.js.
I get minutes (max 1440) and i wanted to format that in hours in specific format.
Something like this:
420 minutes is: 07:00
1140 minutes is: 24:00
451 minutes is: 07:31
const time = 1140;
console.log(getTime(time));
function getTime(minutes) {
let hours = parseInt(minutes / 60);
hours = hours < 10 ? `0${hours}` : hours;
let min = minutes % 60;
min = min < 10 ? `0${min}` : min;
return `${hours}:${min}`;
}
This question already has answers here:
How to format numbers by prepending 0 to single-digit numbers?
(36 answers)
How do I format a date in JavaScript?
(68 answers)
Closed 5 years ago.
I need to add minutes in an specif hour.
It is in js.
I have a hour = 09:30 and need to add more 30minutes, but the output shows me '10:0', one '0' less.
Soma_minutos: function(hour, minutes) {
// This case minutes = 30; hour = 09:30
var tempo, hora_nova, horas = '';
tempo = new Date("T"+hora);
tempo.setTime(tempo.getTime() + minutos*60000);
horas = tempo.getHours().toString(); // 10
minutos = tempo.getMinutes().toString(); // 0
hora_nova = horas + ':' + minutos;
return hora_nova;
},
something like this:
if (minotos.length = 1)
{
minotos = "0" + minotos;
}
This question already has answers here:
JavaScript - Get minutes between two dates
(12 answers)
How can I compare two time strings in the format HH:MM:SS?
(16 answers)
Closed 6 years ago.
I want to display the amount of minutes between the scheduled time and expected time.
This is not to compare, this is to calculate how many minutes there are in different times in both scheduled and expected.
Since both times are displayed as a string, do I need to convert string to a number and then do a comparison?
All I want to return is the difference in time as a number.
Here is my object:
{
station: "Macclesfield",
scheduled: "15:41",
expected: "15:50",
platform: "1"
}
var data = {
station: "Macclesfield",
scheduled: "15:41",
expected: "15:50",
platform: "1"
}
function getTimeDifference(scheduled, expected) {
scheduled = scheduled.split(':'); //get array [hours, minutes]
expected = expected.split(':');
var hours = expected[0] - scheduled[0]; //difference in hours
var minutes = expected[1] - scheduled[1]; //difference in minutes
if (minutes < 0) { //if minutes are negative we know it wasn't a full hour so..
hours--; //subtract an hour
minutes += 60; //add 60 minutes
} //now we're ok
if (hours) //if hours has a value
return hours + ':' + minutes;
return minutes; //hours is 0 so we only need the minutes
}
console.log(getTimeDifference(data.scheduled, data.expected));
data.expected = "16:00";
console.log(getTimeDifference(data.scheduled, data.expected));
data.expected = "17:00";
console.log(getTimeDifference(data.scheduled, data.expected));
var obj = { scheduled: "15:41", expected: "15:50" }
var milliSeconds = Date.parse(`01/01/2011 ${obj.expected}:00`) - Date.parse(`01/01/2011 ${obj.scheduled}:00`)
var minutes = milliSeconds / (1000 * 60)
var hours = milliSeconds / (1000 * 60 * 60)
This question already has answers here:
Convert seconds to HH-MM-SS with JavaScript?
(38 answers)
Closed 6 years ago.
Suppose I have an integer number as a variable. (this number can be any integer number).
Now I want to create a countdown timer based on this number on the page.
To create countDown, I am using jquery-countdownTimer plugin.
A simple usage of this plugin is like this :
$(function(){
$("#hms_timer").countdowntimer({
hours : 3‚
minutes : 10‚
seconds : 10‚
size : "lg"‚
pauseButton : "pauseBtnhms"‚
stopButton : "stopBtnhms"
});
});
As you see , it gets hours , minutes and seconds in 3 separate numbers.
Now my question is how can I convert an integer number to Equivalent hours , minutes and seconds in simplest way?
function getTime(s) {
var secs = parseInt(s, 10); // don't forget the second param
var hours = Math.floor(secs / 3600);
var minutes = Math.floor((secs - (hours * 3600)) / 60);
var seconds = secs - (hours * 3600) - (minutes * 60);
return {
hours: hours,
minutes: minutes,
seconds: seconds
};
}
var time = getTime("3792");
alert("Hours: " + time.hours + "\nMinutes: " + time.minutes + "\nSeconds: " + time.seconds);