Before proceeding, let me introduce what is the role of Date and Time functions?
Role of Date & Time Functions:
i) Time manipulations in projects.
ii) Retrieving time-related information from a database.
iii) This permit time frame selection as per project requirement.
Real-time Use Case:
Let me share with you my experience. Yesterday, I was browsing the internet and scrolling down webpages. I reached one e-learning website. I suddenly received a popped-up message containing "Good Afternoon Message".
I was really shocked for some seconds and questioned my mind how that e-learning website gets to know that it's an afternoon or morning. This makes me so curious about the logic behind it. Then I researched a lot. Finally, I got an answer.
Let's dig into details of Date and time functions:
Date methods include concepts like date values, get time, set time, date objects, get and set methods.
Get and Set methods:
Date methods are associated with "get and set methods". Get methods are used to return a specific portion of date whereas the set methods are used to represent the return portion of a date.
This value present in the date object performs modifications dynamically depending upon the local time and date. However, the date & time get to appear in an alert window through the date object.
var DT = new Date();
Following is the simple program illustrating the "date object creation".
<!DOCTYPE html> <html> <body> <h2>A simple program of Date Object</h2> <p id="demo"></p> <script> var DT = new Date(); document.getElementById("demo").innerHTML = DT; </script> </body> </html>
Output appeared as below:
The above-mentioned output is by default output i.e. JS have used the browser date and time and displayed it in full string.
new Date() new Date(year, month, day, hours, minutes, seconds, milliseconds) new Date(milliseconds) new Date(date string)
In the syntaxes, mentioned-above contains date () constructor, parameters, and arguments. Among them, the parameters inside the brackets are optional whereas the Year, months, hours are the arguments.
Example of new Date(milliseconds):
The output appeared after execution of the above-program is shown below:
Some of the date functions are illustrated in a table along with syntax and descriptions.
|Name of Methods||Syntax||Description|
|Date() method||Date()||This method is used to return the current day's time and date. It is independent of the object.|
|getDate() method||Date.getdate()||This method is used to return the current day's time and date. It is independent of the object.|
|getDay() method||Date.getDay()||This method has been used by developers when there is a need to return the particular day of the week.|
|getFullYear() method||Date.getFullYear()||This method is used when developer needs to return a particular date's year part. The main feature of this method is it always returns an absolute value.|
|getHours() method||Date.getHours()||This method is applicable when there is a need to return the particular hour of the date.|
That's all about Date and time functions. There are many other functions and concepts such as Get functions and Set functions that are also available to perform different operations on the date.
We will discuss them in detail in our further topics. Stay tuned with us.
Don't forget to comment to notify me about the concept which maybe I have missed on this blog.
You can revisit our previous topics to get cleared entire doubts.