getMinutes(). This method is part of the Date object and is used to retrieve the minutes from a specific date and time.
What is getMinutes() Method?
let date = new Date(); let minutes = date.getMinutes(); console.log(minutes); // Outputs: current minute
In this example, we create a new Date object and then use
getMinutes() to retrieve the current minute according to your system’s local time.
Tutorial: Using getMinutes() Method
Step 1: Create a Date Object
To start with, you need to create a new Date object. Here’s how:
let currentDate = new Date();
Step 2: Use getMinutes() Method
You can now use
getMinutes() on your newly created Date object:
let currentMinute = currentDate.getMinutes(); console.log(currentMinute);
This will output the current minute as per your system’s local time.
A Few Things To Remember About getMinutes()
- No Parameters:
getMinutes()method does not take any parameters.
- Return Value:
It returns an integer value between 0 and 59, representing the minutes in the given date according to local time.
- Doesn’t Change Original Date:
getMinutes()method does not modify the Date object it’s invoked on. It simply retrieves data from it.
getMinutes() method is a simple yet powerful tool for working with dates and times. Whether you’re building a digital clock or just need to pull the minute value from a timestamp, this method can come in handy. Happy coding!