datevec(d: ,fmt?: string,): array | matrix
Convert date and time to an array of components.
Converts a given date and time to an array of components such as year, month, day, hour, minute, second, and millisecond. The function supports both date strings and Unix timestamps as input. Input is restricted to either a single value or an array (1D array).
Convert a date string to an array
Convert a date string to an array
import { assertEquals } from "jsr:@std/assert"; assertEquals(datevec('2015-01-01 03:34:05', 'YYYY-MM-DD HH:mm:ss'), [2015, 1, 1, 3, 34, 5, 0]);
Convert an array of date strings to an array of arrays
Convert an array of date strings to an array of arrays
import { assertEquals } from "jsr:@std/assert"; assertEquals(datevec(['31-12-2014', '31-01-2015'], 'DD-MM-YYYY'), [[2014, 12, 31, 0, 0, 0, 0], [2015, 1, 31, 0, 0, 0, 0]]);
Convert a Unix timestamp to an array
Convert a Unix timestamp to an array
import { assertEquals } from "jsr:@std/assert"; assertEquals(datevec(1428236430), [2015, 4, 5, 12, 20, 30, 0]);
Convert an array of Unix timestamps to an array of arrays
Convert an array of Unix timestamps to an array of arrays
import { assertEquals } from "jsr:@std/assert"; assertEquals(datevec([1609459200, 1612137600]), [[2021, 1, 1, 0, 0, 0, 0], [2021, 2, 1, 0, 0, 0, 0]]);
Convert a Unix timestamp with milliseconds to an array
Convert a Unix timestamp with milliseconds to an array
import { assertEquals } from "jsr:@std/assert"; assertEquals(datevec(1428236430579), [2015, 4, 5, 12, 20, 30, 579]);
Convert a date string with time zone to an array (converts to UTC)
Convert a date string with time zone to an array (converts to UTC)
import { assertEquals } from "jsr:@std/assert"; assertEquals(datevec('2023-08-25T14:45:00+02:00', 'YYYY-MM-DDTHH:mm:ssZ'), [2023, 8, 25, 12, 45, 0, 0]);