10 examples of 'javascript parse date format yyyy-mm-dd' in JavaScript

Every line of 'javascript parse date format yyyy-mm-dd' 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
46function parseDate(date) {
47 var re = date.match("([0-9]+)-([0-9]+)-([0-9]+) ([0-9]+):([0-9]+):.*");
48 return (re[2] + '/' + re[3] + '/' + re[1] + ' ' + re[4] + ':' + re[5]);
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

567function parseDate(date) {
568 if (date) {
569 try { return new Date(Date.parse(date)); }
570 catch (e) { /* ignore invalid dates */ }
571 }
572}
105export function parseDate(d: string): Date {
106 const matches = d.match(/\d+/);
107 return new Date(parseInt(matches![0], 10));
108}
120function parseDate (date) {
121 date = date.split('-')
122
123 var year = parseInt(date[0])
124 var month = parseInt(date[1]) - 1
125 var day = parseInt(date[2])
126
127 return new Date(year, month, day)
128}
46function parseDate(str) {
47 if (Y.Lang.isNull(str) || Y.Lang.isUndefined(str))
48 return null;
49 var parts = str.split(/[- :]/);
50 if ( parts.length < 3 )
51 return null;
52 while ( parts.length < 6 )
53 parts.push(0);
54 return new Date(parts[0], parts[1]-1, parts[2], parts[3], parts[4], parts[5]);
55}
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}
20export default function parseDate(
21 date: string | number | Date,
22 mask = 'default',
23 locale = zhCN
24): Date {
25 if (date instanceof Date) {
26 return date;
27 }
28
29 if (typeof date === 'number') {
30 return new Date(date);
31 }
32
33 mask = mask || 'default';
34
35 const ret = parse(date, mask, locale);
36
37 if (!ret) {
38 return null;
39 }
40
41 return ret;
42}
23function parseDate(dateStr) {
24 return moment(dateStr).toDate();
25}
43function parseStartDate (date: ?string) {
44 if (!date) {
45 return undefined;
46 }
47 if (new Date(date).toString() === 'Invalid Date') {
48 return undefined;
49 }
50 return new Date(date);
51}
17public static parse(date: any): Date {
18 return moment(date).toDate();
19 //return moment.utc(date).add('milliseconds', timeZoneOffset).toDate();
20}

Related snippets