10 examples of 'html today's date' in JavaScript

Every line of 'html today's date' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
43function getToday(){
44 var date = new Date()
45 var day = pad(date.getDate())
46 var month = pad((date.getMonth()+1))
47 var year = date.getFullYear()
48 return month + '/' + day + '/' + year
49}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

235function formatTodayDate () {
236 const date = new Date();
237 const day = ('0' + date.getDate()).slice(-2);
238 const month = ('0' + (date.getMonth() + 1)).slice(-2);
239 const year = date.getFullYear();
240
241 return `${year}-${month}-${day}`;
242}
6function getToday() {
7 var now = new Date();
8 now.setHours(0);
9 now.setMinutes(0);
10 now.setSeconds(0);
11 now.setMilliseconds(0);
12 return now;
13}
22function createYesterdayString() {
23 var yesterday = new Date();
24 yesterday.setDate(yesterday.getDate() - 1);
25 return formatDate(yesterday);
26}
86function getDate(date) {
87 var yyyy = date.getFullYear().toString();
88 var mm = (date.getMonth() + 1).toString();
89 var dd = date.getDate().toString();
90
91 return (dd[1] ? dd : "0" + dd[0]) + "." + (mm[1] ? mm : "0" + mm[0]) + "." + yyyy;
92}
5export function dayStart(date) {
6 const now = date || new Date();
7 return setTime(now);
8}
90function longdate(date, showtime) {
91 return format_date(date, months, showtime)
92}
24function formatDay(date) {
25 d = new Date(date * 1000);
26 return d.getDate() + " " + months[d.getMonth()];
27}
37function getDate(strDate) {
38 /* istanbul ignore next */
39 return moment(strDate).format('YYYY-MM-DD')
40}
19function getDate() {
20 // GET CURRENT DATE
21 var date = new Date();
22
23 // GET YYYY, MM AND DD FROM THE DATE OBJECT
24 var yyyy = date.getFullYear().toString();
25 var mm = (date.getMonth()+1).toString();
26 var dd = date.getDate().toString();
27
28 // CONVERT mm AND dd INTO chars
29 var mmChars = mm.split('');
30 var ddChars = dd.split('');
31
32 // CONCAT THE STRINGS IN YYYY-MM-DD FORMAT
33 var datestring = yyyy + '-' + (mmChars[1]?mm:"0"+mmChars[0]) + '-' + (ddChars[1]?dd:"0"+ddChars[0]);
34
35 return datestring ;
36}

Related snippets