10 examples of 'moment get day' in JavaScript

Every line of 'moment get day' 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
67getDayOfWeek(date: Date): number {
68 return date.getDay();
69}
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

157getDay() { return !(this.value instanceof Date) ? NaN : this.value.getDay(); }
78getDay() {
79 return moment().format(`dddd`);
80}
40static dayOfWeek (date) {
41 var day = date.getDay()
42 return {
43 1: 'Mon',
44 2: 'Tue',
45 3: 'Wed',
46 4: 'Thu',
47 5: 'Fri',
48 6: 'Sat',
49 0: 'Sun'
50 }[day]
51}
76public getDayOfWeek(date: Moment): number {
77 return this.clone(date).day();
78}
118function getDay(day: number) {
119 const t = new Date(time);
120 t.setDate(t.getDate() + day);
121 const m = t.getMonth() + 1;
122 return t.getFullYear() + '-' + m + '-' + t.getDate();
123}
74public startOfDay(date: Moment) {
75 return date.clone().startOf('day');
76}
691startOfDay(moment = this.moment) {
692 return moment.clone().startOf(Unit.DAY)
693}
12getLastMonday(): Date {
13 let nowDate: Date = this.clock.getDate();
14 let dayOfWeek = nowDate.getDay() ? nowDate.getDay() : 7;
15 let daysOffsetInMillis = (dayOfWeek - 1) * WeekCalculator.MILLIS_IN_DAY;
16 let lastMonday = new Date(nowDate.getTime() - daysOffsetInMillis);
17
18 lastMonday.setHours(0);
19 lastMonday.setMinutes(0);
20 lastMonday.setSeconds(0);
21 lastMonday.setMilliseconds(0);
22
23 return lastMonday;
24}
120export function getStartOfDay(date: moment.MomentInput): Date {
121 return moment(date)
122 .startOf('day')
123 .startOf('hour')
124 .startOf('minute')
125 .startOf('second')
126 .local()
127 .toDate();
128}

Related snippets