Choice 1 – Utilizing toLocaleDateString()
You possibly can simply implement this feature to get the present date.
Choice 2 – Utilizing Date()
It’s a constructor used to create a brand new date object defining at present’s date and time. With this class, you’ve got many utility strategies that assist acquire the present month, date, and yr. Similar to talked about above, it’s a must to create a var saved within the new Date(). The getDate() is used to return the day on the month, getMonth() works to return the month, getFullYear() outcomes the total yr. You want to set the variable for every, after which to get the present date in month, day, and yr format, name the go surfing the console every with a $ signal.
That is one other approach to acquire the data within the format you want.
Choice 3 – Utilizing Second.JS
Second.js is the library that almost all programmers have already put in. It’s one other easiest approach to get the present date. On this library, the format() technique is used to simply accept the format you need for parsing a second. You possibly can code utilizing second.js by establishing the second because the variable saved within the require(). After this, simply specify the format you need within the format(), after which name the console log to acquire the present date.
Choice 4 – Get the date with the time
More often than not that you must have show time on the web site together with the present date. It’s the best choice that may assist programmers get the present date and time as properly. To get hours, minutes, and seconds with date, create the brand new Date() and retailer it in a variable. Use the variable to get full yr, present month, and present date. For acquiring time, set the variable to get time within the hh:mm:ss format. Name each variable collectively to get the output you wish to have.
Choice 5 – Utilizing slice()
It’s a technique used to acquire the date that works with the toJSON() technique. The slice() helps you get the ten characters at first. You want to let currentDate set to the brand new Date() utilizing toJSON and slice() from 0-10 vary. Once you name the log, you get the present date.
If you’re utilizing JSON, then you should utilize the above technique to acquire the present date.
Leave a Reply