javascript String to Get Hours and Minutes

javascript String to Get Hours and Minutes

In this Post We Will Explain About is javascript String to Get Hours and Minutes With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to javascript get hours and Minutes in 12 hour format Example

In this post we will show you Best way to implement convert hours to minutes in javascript, hear for javascript getminutes two digitswith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Read Also:  Laravel Encryption Decryption using Crypt class

Simple javascript Get Hours and Minutes Example

In this Example to Learn, String To get Hours and Minutes specific split to array convert. and then two difference hours to get particuler same day and validation per day select duration using javascript.

Make a HTML file and define markup

<hr />
<b>Example 1 : JavaScript Get Hours and Minutes using String</b>
<h2 id="number"></h2>
<h2 id="minute"></h2>
<hr />
<b>Example 2: JavaScript Get Hours and Minutes using String</b>

<h2 id="get_hour"></h2>
<h2 id="get_mini"></h2>
<hr />
<div id="buttons">
    <ul>
        <li><a href="https://www.pakainfo.com/" target="_blank">Live24u</a></li>
        <li><a href="https://www.pakainfo.com/tutorial/" target="_blank">w3free</a></li>
        <li><a href="https://www.pakainfo.com/tutorial/" target="_blank">Tutorials</a></li>
        <li><a href="https://www.pakainfo.com/tools/live-editor.html" target="_blank">Editor</a></li>
        <li><a href="https://www.pakainfo.com/tools/character-letter-word-counter.html" target="_blank">Counter</a></li>
        <li><a href="https://www.pakainfo.com/tools/free-online-difference-tools.html" target="_blank">Difference</a></li>
    </ul>
</div>

Make a js file and define scripting

var html= "10 hour and 10 minute";
var mini =  html.substr(html.length - 10);
var number = parseInt(html.match(/-*[0-9]+/));
var mini = parseInt(mini.match(/-*[0-9]+/));

if(html.includes("and"))
{
	 document.getElementById('number').innerHTML="First hours: "+number;
   document.getElementById('minute').innerHTML="First minutes: "+mini;
}
else if(html.includes("hour"))
{
	document.getElementById('number').innerHTMLinnerHTML="First hours: "+number;
}
else if(html.includes("minute"))
{
	 document.getElementById('minute').innerHTML="First minutes: "+mini;
}

var time="18:00";
var timeArray = time.split(" ");
timeArray = timeArray[0].split(":");

var get_hour = parseInt(timeArray[0]);
var get_mini = parseInt(timeArray[1]);

document.getElementById('get_hour').innerHTML="Second get_hour: "+get_hour;
document.getElementById('get_mini').innerHTML="Second get_mini: "+get_mini;

var total_hours_get = get_hour+number;
if(total_hours_get <= 24)
{
	alert(total_hours_get);
}
else
{
 alert("false");
}

Example

I hope you have Got What is convert hours to minutes in javascript And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.