10 examples of 'parseiso date-fns' in JavaScript

Every line of 'parseiso date-fns' 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
9function date (isostring) {
10 return isostring
11}
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

189public resolveISOString(value: string): number {
190
191 let todayInMS: number = Date.UTC(this.today.getFullYear(), this.today.getMonth(), this.today.getDate());
192 let dt: string[] = value.split("-");
193
194 let year: number, month: number, day: number;
195 if (dt.length >= 3) {
196 year = parseInt(dt[0]);
197 month = parseInt(dt[1]) - 1;
198 day = parseInt(dt[2]);
199 } else if (dt.length >= 2) {
200 month = parseInt(dt[0]) - 1;
201 day = parseInt(dt[1]);
202 } else {
203 day = parseInt(dt[0]);
204 }
205
206 if (month && (month < 0 || month > 12)) throw new Error("Invalid value for month");
207 if (day && (day < 0 || day > 31)) throw new Error("Invalid value for day");
208
209 let inputInMS: number = 0;
210 if (year) {
211 // full date with year (e.g. 2016-10-24)
212 inputInMS = Date.UTC(parseInt(dt[0]), parseInt(dt[1]) - 1, parseInt(dt[2]));
213 } else if (month) {
214 // month and day (eg. 10-24)
215
216 inputInMS = Date.UTC(this.today.getFullYear(), parseInt(dt[0]) - 1, parseInt(dt[1]));
217 } else if (day) {
218 // just a day
219 inputInMS = Date.UTC(this.today.getFullYear(), this.today.getMonth(), parseInt(dt[0]));
220 } else {
221 throw new Error("Failed to parse the date");
222 }
223
224 let result: number = Math.floor((inputInMS - todayInMS) / (1000 * 60 * 60 * 24));
225 return result;
226}
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}
28export function formatDateTimeStringISO(dateTimeString) {
29 if (!dateTimeString) {
30 return blankValue;
31 }
32 const parts = new Intl.DateTimeFormat('en', {
33 year: 'numeric',
34 month: '2-digit',
35 day: '2-digit',
36 hour: '2-digit',
37 minute: '2-digit',
38 second: '2-digit',
39 hour12: false,
40 }).formatToParts(new Date(dateTimeString));
41 const keys = {};
42 for (const {type, value} of parts) {
43 keys[type] = value;
44 }
45 return `${keys.year}-${keys.month}-${keys.day} ${keys.hour}:${keys.minute}:${keys.second}`;
46}
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}
3export function isoDate(date: Date): string{
4 return date_format("isoDateTime")
5}
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}
46parse(value, formatString) {
47 if (value === '') {
48 return null;
49 }
50
51 return dateFnsParse(value, formatString, new Date());
52}
105export function parseDate(d: string): Date {
106 const matches = d.match(/\d+/);
107 return new Date(parseInt(matches![0], 10));
108}
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}

Related snippets