- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Methods in Date()
getHours() − The current hour is shown using the today variable. A 24-hour clock is used in this.
getMinutes() − Shows the minute reading as it is currently.
getSeconds() − Shows the second reading as it is currently.
var date = new Date();
In the above syntax, Date() is the constructor and we have used it to create the object of the Date class.
Now let us see the way to extract minutes.
Using the getMinutes() Method from the Current Time
Here, we will learn to extract minutes from the current time.
Follow the syntax below to use the getMinutes() feature.
var date = new Date(); var minutes = date.getMinutes();
Here, the current time is taken at run time using the new Date() method, and the getMinutes() is called from this value to obtain the current minutes.
STEP 1 − Invoke a new Date() without any specific time as a parameter for getting the current time.
STEP 2 − Use getMinutes() in the current time to display the minutes.
In the below example, we have created an empty Dom element to display the output. Then a script has been written. Here we are trying to extract minutes from the current time. The syntax is the same as given above. Then getMinutes() extracts the value and we get the output displayed in the inner HTML.
<html> <body> <h2>Using the <i>current time's getMinutes()</i> script feature.</h2> <p id="idCurrent"></p> <script> var curDate = new Date(); var curDisplay = document.getElementById('idCurrent'); curDisplay.innerHTML = "Minutes Current " + curDate.getMinutes(); </script> </body> </html>
Using the getMinutes() Method from a Specific Time
Here, we will learn to extract minutes from a specific or custom time.
Follow the syntax below to use the getMinutes feature.
var date = new Date(Month dd, yyyy hh:mm:ss); var minutes = date.getMinutes();
Here, the current time is taken by passing an argument to the new Date() method like in the syntax above and the getMinutes() is called from this value to obtain the specific minutes.
In the below example, we have created an empty Dom element to display the output. Then a script has been written. Here we are trying to extract and display minutes from a specific time. The syntax is as given above. We need to give it as a parameter to the new Date() function here since we need to extract the minutes value from a specific time. Then getMinutes() extracts the value and we get the output displayed in the inner HTML.
<html> <body> <h2>Using <i>specific time's getMinutes()</i> script feature</h2> <p id="idDisplay"></p> <script> var varDate = new Date("November 05, 1985 18:25:01"); var varDisplay = document.getElementById('idDisplay'); varDisplay.innerHTML = "Minutes Specific " + varDate.getMinutes(); </script> </body> </html>
- Related Articles
- Subtract minutes from current time using Calendar.add() method in Java
- How to return the time-zone offset in minutes for the current locale?
- Java Program to add minutes to current time using Calendar.add() method
- Convert number INT in minutes to TIME in MySQL?
- How to get current time from Network provider in android?
- Python Pandas - Extract month number from the DateTimeIndex with specific time series frequency
- How to extract number from string in R data frame?