10 examples of 'date split in javascript' in JavaScript

Every line of 'date split 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
this disclaimer
382function splitDate(date) {
383 var month, year, leadingDigit;
384
385 date = date.replace(/[\/\-\s]/g, '');
386 leadingDigit = date.charAt(0);
387
388 if (date.length === 0) {
389 month = year = '';
390 } else if (leadingDigit === '0' || leadingDigit === '1') {
391 month = date.slice(0, 2);
392 year = date.slice(2);
393 } else {
394 month = '0' + leadingDigit;
395 year = date.slice(1);
396 }
397
398 return {month: month, year: year};
399}
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

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}
77function stringToDate(strDate) {
78 var dateParts = strDate.split("-");
79 return new Date(dateParts[0], (dateParts[1] - 1), dateParts[2]);
80}
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}
13export function dateToValues(value) {
14 value = value ? value.split("-") : [];
15 return value;
16}
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}
64function toDate (s) {
65 let a = s.split(/[^0-9]/)
66 let dateStr = a[0] + '-' + a[1] + '-' + a[2] + 'T' + a[3] + ':' + a[4] + 'Z'
67
68 return new Date(dateStr)
69}
105export function parseDate(d: string): Date {
106 const matches = d.match(/\d+/);
107 return new Date(parseInt(matches![0], 10));
108}
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}
14function formatDate(date, split) {
15 var year = date.getFullYear()
16 var month = date.getMonth() + 1
17 var day = date.getDate()
18 return [year, month, day].map(formatNumber).join(split || '')
19}

Related snippets