10 examples of 'moment todate' in JavaScript

Every line of 'moment todate' 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
109function toDate(type) {
110 var params = {};
111 if (type === 'yesterday') {
112 params.start = new Moment().subtract(1, 'day').startOf('day').toDate();
113 params.end = new Moment().subtract(1, 'day').endOf('day').toDate();
114 } else if (type === 'weekly' || type === 'week') {
115 params.start = new Moment().startOf('week').toDate();
116 params.end = new Moment().endOf('week').toDate();
117 } else if ( type === 'today' || type === 'day') {
118 params.start = new Moment().startOf('day').toDate();
119 params.end = new Moment().endOf('day').toDate();
120 } else if ( type === 'monthly' || type === 'month') {
121 params.start = new Moment().startOf('month').toDate();
122 params.end = new Moment().endOf('month').toDate();
123 } else if ( type === 'last_seven_day' || type === 'last_seven_days' ||type === 'last_7_days') {
124 params.start = new Moment().subtract(7, 'day').startOf('day').toDate();
125 params.end = new Moment().endOf('day').toDate();
126 } else if ( type === 'last_three_day' || type === 'last_three_days' || type === 'last_3_days') {
127 params.start = new Moment().subtract(3, 'day').startOf('day').toDate();
128 params.end = new Moment().endOf('day').toDate();
129 } else if ( type === 'last_fifteen_day' || type === 'last_fifteen_days' || type === 'last_15_days') {
130 params.start = new Moment().subtract(15, 'day').startOf('day').toDate();
131 params.end = new Moment().endOf('day').toDate();
132 } else if (type === 'last_month') {
133 params.start = new Moment().subtract(1, 'month').startOf('day').toDate();
134 params.end = new Moment().endOf('day').toDate();
135 }
136 params.diff = Moment(params.end).diff(params.start, 'day') + 1;
137 return params;
138}
13function dateToDateTime(d) {
14 if (d) {
15 var date = moment(d);
16 // return null if not is valid
17 if (!date.isValid()) return null;
18 // return data in datetime format
19 return date.format('YYYY-MM-DD HH:mm:ss');
20 } else {
21 return null;
22 }
23}
9export function toDate () {
10 return new Date(this.valueOf());
11}
17public static parse(date: any): Date {
18 return moment(date).toDate();
19 //return moment.utc(date).add('milliseconds', timeZoneOffset).toDate();
20}
81public toDate(date: Date): Calendario {
82 return calendario(this._events, this.options, date)
83}
20toDate(): Date {
21 return new Date(this.year, this.month, this.date);
22}
39function _toMoment (date) {
40 return moment(date).tz(TIME_ZONE)
41}
23function parseDate(dateStr) {
24 return moment(dateStr).toDate();
25}
13static moment2CalendarDate(moment: Moment): OgCalendarDate {
14 return { year: moment.get('y'), month: moment.get('M'), date: moment.get('D') };
15}
170dateToString(date: Date | Moment | string): string {
171 if (date instanceof Date) {
172 return date.toISOString();
173 }
174 return moment(date).toISOString();
175}

Related snippets