JavaScript convert time(hours, minutes, seconds and miliseconds); Through this tutorial, i am going to show you how to convert hours to minutes, hours to seconds, hours to milliseconds, minutes to seconds, minutes to Milliseconds, seconds to milliseconds, date to milliseconds and seconds to hh mm ss time in JavaScript with the help of examples.
Convert hours minutes seconds milliseconds JavaScript
Here, i will take following examples to convert hours to minutes, hours to seconds, hours to milliseconds, minutes to seconds, minutes to Milliseconds, seconds to milliseconds, date to milliseconds and seconds to hh mm ss time in JavaScript; as shown below:
- JavaScript convert hours to minutes
- Convert hours to seconds in javascript
- Convert hours to milliseconds javascript
- Convert minutes to seconds in javascript
- Convert minutes to Milliseconds in javascript
- Convert seconds to milliseconds javascript
- Convert date to milliseconds javascript
- JavaScript convert seconds to hh mm ss
1 – JavaScript convert hours to minutes
Using javaScript Math.floor() function to convert hours to minutes in javascript; as shown below:
function convertHourstoMinute(hours) { return Math.floor(hours * 60); }
See the following example to convert hours to minutes in javascript; as shown below:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>javascript convert hours to minutes</title> </head> <body> <script type = "text/javascript"> function convertHourstoMinute(hours) { return Math.floor(hours * 60); } var minutes = convertHourstoMinute(2); // convert hours into minutes javascript document.write( "javascript convert hours to minutes :- " + minutes ); </script> </body> </html>
2 – Convert hours to seconds in javascript
Using the following function, you convert hours to seconds in javascript; as shown below:
function convertHourstoSeconds(hours) { return Math.floor(hours * 60 * 60); }
See the following example to convert hours to seconds in javascript; as shown below:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>javascript convert hours to seconds<</title> </head> <body> <script type = "text/javascript"> function convertHourstoSeconds(hours) { return Math.floor(hours * 60 * 60); } var hoursToSeconds = convertHourstoSeconds(2); // convert hours into second javascript document.write( "Result of converting hours to seconds :- " + hoursToSeconds ); </script> </body> </html>
3 – Convert hours to milliseconds javascript
Use the following function to convert hours to milliseconds in javascript; as shown below:
function convertHourstoMilliSecond(hours) { return Math.floor(hours * 60 * 60 *1000); }
See the following example to convert hours to milliseconds in javascript; as shown below:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>convert hours to milliseconds javascript</title> </head> <body> <script type = "text/javascript"> function convertHourstoMilliSecond(hours) { return Math.floor(hours * 60 * 60 *1000); } var hoursToMilliSecond = convertHourstoMilliSecond(2); // convert hours into milli second javascript document.write( "Result of converting hours to milliseconds :- " + hoursToMilliSecond ); </script> </body> </html>
4 – Convert minutes to seconds in javascript
Use the following function to convert minutes to seconds in javascript; as shown below:
function convertMinutestoSeconds(minutes) { return Math.floor(minutes * 60); }
See following example to convert minutes to seconds in javascript; as shown below:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>convert minutes to seconds in javascript</title> </head> <body> <script type = "text/javascript"> function convertMinutestoSeconds(minutes) { return Math.floor(minutes * 60); } var minutesToSeconds = convertMinutestoSeconds(2); // convert minutes to second javascript document.write( "Result of converting minutes to seconds :- " + minutesToSeconds ); </script> </body> </html>
5 – Convert minutes to Milliseconds in javascript
Use the following function to convert minutes to milliseconds in javascript; as shown below:
function convertMinutestoMilliSeconds(minutes) { return Math.floor(minutes * 60 * 1000); }
See the following example to convert minutes to milliseconds in javascript; as shown below:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>convert minutes to Milli seconds in javascript</title> </head> <body> <script type = "text/javascript"> function convertMinutestoMilliSeconds(minutes) { return Math.floor(minutes * 60 * 1000); } var minutesToMilliSeconds = convertMinutestoMilliSeconds(2); // convert minutes to second javascript document.write( "Result of converting minutes to milli seconds :- " + minutesToMilliSeconds ); </script> </body> </html>
6 – Convert seconds to milliseconds javascript
Use the following function to convert seconds to milliseconds in javascript; as shown below:
function convertSecondstoMilliSeconds(seconds) { return Math.floor(seconds * 1000); }
See following example to convert seconds to milliseconds in javascript; as shown below:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>convert seconds to Milli seconds in javascript</title> </head> <body> <script type = "text/javascript"> function convertSecondstoMilliSeconds(seconds) { return Math.floor(seconds * 1000); } var secondsToMilliSeconds = convertSecondstoMilliSeconds(2); // convert minutes to second javascript document.write( "Result of converting seconds to milli seconds :- " + secondsToMilliSeconds ); </script> </body> </html>
7 – Convert date to milliseconds javascript
See the following to convert date string to milliseconds javascript using the javascript getTime() method; as shown below:
var date = new Date(); var milliseconds = date.getTime();
See the following example to convert date string to milliseconds javascript using the javascript getTime() method; as shown below:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>convert date to Milliseconds in javascript</title> </head> <body> <script type = "text/javascript"> var date = new Date(); var milliseconds = date.getTime(); document.write( "Result of converting date to milliseconds :- " + milliseconds ); </script> </body> </html>
8 – JavaScript convert seconds to hh mm ss
Use the following function to convert seconds to hh mm ss format in javascript; as shown below:
function convertSecondsTo(sec) { var hours = Math.floor(sec / 3600); var minutes = Math.floor((sec - (hours * 3600)) / 60); var seconds = sec - (hours * 3600) - (minutes * 60); seconds = Math.round(seconds * 100) / 100 var result = (hours < 10 ? "0" + hours : hours); result += "-" + (minutes < 10 ? "0" + minutes : minutes); result += "-" + (seconds < 10 ? "0" + seconds : seconds); return result; }
See following example to convert seconds to hh mm ss format in javascript; as shown below:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>javascript convert seconds to hh mm ss</title> </head> <body> <script type = "text/javascript"> function convertSecondsTo(sec) { var hours = Math.floor(sec / 3600); var minutes = Math.floor((sec - (hours * 3600)) / 60); var seconds = sec - (hours * 3600) - (minutes * 60); seconds = Math.round(seconds * 100) / 100 var result = (hours < 10 ? "0" + hours : hours); result += "-" + (minutes < 10 ? "0" + minutes : minutes); result += "-" + (seconds < 10 ? "0" + seconds : seconds); return result; } var secondsTo = convertSecondsTo(1000); // convert seconds in HH-MM-SS format javascript document.write( "Result of converting to seconds in HH-MM-SS format :- " + secondsTo ); </script> </body> </html>
Be First to Comment