10 examples of 'set today date' in JavaScript

Every line of 'set today 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
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}
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

171function setDate (date, day) {
172 return _getMoment(date).date(day).toDate()
173}
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}
362function preDay(date) {
363 return new Date(date.getTime() - 24 * 60 * 60 * 1000)
364}
562setDate(date) {
563 if (Calendar.sameDay(date, this._date))
564 return;
565 this._date = date;
566 this._sync();
567}
191export function getDayStart() {
192 return new Date(new Date(new Date().toDateString()).getTime())
193}
20toDate(): Date {
21 return new Date(this.year, this.month, this.date);
22}
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}
23public static getDate(currentDatePlusDays) {
24 const currentTimeInMs = new Date().getTime();
25 return new Date(currentTimeInMs + (currentDatePlusDays * DateHelper.dayDurationInMs));
26}
3export function currentDate(): string {
4 return moment().format('[Today is a] dddd');
5}

Related snippets