10 examples of 'date class in javascript' in JavaScript

Every line of 'date class in javascript' 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
5function standardDate(d){
6 var date = new Date(d);
7 date.setHours(0,0,0,0);
8 return date;
9}
96export function createDate(date) {
97 if (typeof date === 'string') {
98 const [dateString, timeString] = date.split(' ');
99 const args = dateString.split('-');
100 args[1] = args[1] - 1;
101 if (timeString) {
102 args.push.apply(args, timeString.split(':'));
103 }
104 return new Date(...args);
105 }
106 if (!date) return new Date();
107 return new Date(date);
108}
182function Date_Time(julian_date) {
183 return new Date((julian_date - 2440587.5) * 86400000.);
184}
83_getDate(date, minDate = this.state.minDate, maxDate = this.state.maxDate) {
84 // If no date is provided then use current date
85 // Make sure we constrain it to the min and max
86 const current = (date instanceof Date) ? date : new Date();
87
88 if (minDate && current < minDate) {
89 return minDate;
90 }
91
92 if (maxDate && current > maxDate) {
93 return maxDate;
94 }
95
96 return current;
97}
65function getDateObj(myDate: any): Date | null {
66 if (myDate == null) {
67 return null;
68 }
69
70 if (myDate instanceof String || typeof myDate === 'string') {
71 return new Date('' + myDate);
72 }
73
74 // A Firebase Timestamp format
75 if (myDate && (myDate.seconds >= 0 || myDate.seconds < 0) && (myDate.nanoseconds >= 0 || myDate.nanoseconds < 0)) {
76 return new Date(myDate.toDate());
77 }
78
79 return myDate;
80}
567function parseDate(date) {
568 if (date) {
569 try { return new Date(Date.parse(date)); }
570 catch (e) { /* ignore invalid dates */ }
571 }
572}
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}
200public toJavaScriptDate(implicitTimezone = undefined): Date {
201 const timezoneToUse =
202 this._timezone || implicitTimezone || DayTimeDuration.fromTimezoneString('Z');
203 return new Date(
204 Date.UTC(
205 this._years,
206 this._months - 1,
207 this._days,
208 this._hours - timezoneToUse.getHours(),
209 this._minutes - timezoneToUse.getMinutes(),
210 this._seconds + this.secondFraction
211 )
212 );
213}
24function parseDate(dateCode) {
25 const {y, m, d, H, M, S} = XLSX.SSF.parse_date_code(dateCode)
26
27 return new Date(`${y}/${m}/${d} ${H}:${M}:${S}`).getTime()
28}
12toJsDate() {
13 return new Date(this._value.getTime()); // return a clone.
14}

Related snippets