To start with, we’ll create a brand new object of Date() and declare a variable named “present” and assign the brand new Object of Date() to a “present” variable.
After assigning, let’s take a look on the object Date what does it have for us.
Alright! It seems to be fairly cool in a very good format. However, how about if we need to get solely the 12 months from the whole date? We will use the built-in perform getFullYear() for getting the 12 months solely.
Equally, if we need to extract solely the 12 months, we will use the built-in perform getMonths() for getting the month solely.
There looks as if a difficulty. This isn’t the eighth month(August)! As we will see within the above full output for the brand new Date object. That is September. Effectively, that is due to the digital(0-11). So, we have now so as to add “1” to it for getting the suitable month each time.
That is wonderful now.
Identical to for the 12 months, we will do the identical for the date. For instance, to extract or get solely the date, we will use the built-in perform getDate().
Identical to a date, we have now built-in features for extracting the specified piece of time. For instance, if we need to get or extract the hours solely, from the entire present time, we will use the built-in perform getHours().
The identical goes for the minutes. To extract minutes solely, we will use getMinutes().
To extract seconds solely, we will use getSeconds().
Superior built-in features
Right here we have now some superior built-in features to get the date and time in a reasonably clear and good formatted string. For instance, with a view to get solely the time, not the date, within the type of string we will use the built-in perform toLocaleTimeString() to our function.
present.toLocaleTimeString(); // “2:42:07 PM”
And, if we need to extract solely the time within the type of string. We will use the built-in perform toLocaleDateString().
present.toLocaleDateString(); // “9/29/2020”
And, if we need to extract each the date and time in a single string, we will use the built-in perform toLocaleString().
present.toLocaleString(); // “9/29/2020, 2:42:07 PM”
So, that is how we will get the date and time utilizing the built-in date object and extract the required months, years, or minutes utilizing totally different strategies.
linux "date -d",bash is an acronym for ________,cal command in linux,set date command in linux,unix date attributes,which command will find all read only files