typed-xlsx
Core Concepts

Dates and Time Zones

How typed-xlsx turns a JavaScript Date into an Excel date, and the timeZone option for dates built in local time or a named zone.

An Excel date is a number of days with no time zone: 46095 is 14 March 2026, wherever the file is opened. A JavaScript Date is an instant. To write one, typed-xlsx has to read its calendar date and time in some zone.

By default it reads them in UTC. That is right for dates built with Date.UTC(), parsed from "2026-03-14", or returned by APIs as UTC timestamps. It is wrong for dates built in local time: in Paris, new Date(2026, 2, 14) is 13 March 23:00 UTC, so the cell shows 13 March.

Where the Date comes fromtimeZone
Date.UTC(…), new Date("2026-03-14"), ISO strings ending in Z"utc" (default)
new Date(2026, 2, 14), a browser date picker, pg or mysql2 DATE"local"
a timestamp to show as the clock in one place, whatever the serveran IANA name, "Europe/Paris"

Set it on the workbook

import { 
createExcelSchema
,
createWorkbook
} from "typed-xlsx";
type
Booking
= {
guest
: string;
arrival
:
Date
};
const
schema
=
createExcelSchema
<
Booking
>()
.
column
("guest", {
accessor
: "guest" })
.
column
("arrival", {
accessor
: "arrival",
format
: "yyyy-mm-dd" })
.
build
();
const
workbook
=
createWorkbook
({
timeZone
: "local" });
workbook
.
sheet
("Bookings").
table
("bookings", {
schema
,
rows
: [{
guest
: "Ada",
arrival
: new
Date
(2026, 2, 14) }],
});

createWorkbookStream() takes the same option. An unknown zone name throws when the workbook is created.

Override it on a column

A column's timeZone wins over the workbook's. Use it when one column holds UTC timestamps and another holds local dates:

import { 
createExcelSchema
,
createWorkbook
} from "typed-xlsx";
type
Flight
= {
departsAt
:
Date
;
loggedAt
:
Date
};
const
schema
=
createExcelSchema
<
Flight
>()
.
column
("departsAt", {
accessor
: "departsAt",
format
: "yyyy-mm-dd hh:mm" })
.
column
("loggedAt", {
accessor
: "loggedAt",
format
: "yyyy-mm-dd hh:mm",
timeZone
: "utc" })
.
build
();
const
workbook
=
createWorkbook
({
timeZone
: "America/New_York" });

What it changes

The Date is converted once, when it becomes a cell. Everything built from cells uses the converted date: the cell value, auto width, summary cells that return a Date, Excel table formula values and totals, pivot date groups, and chart caches. Date bounds in a column's data validation are converted with the column's zone too.

transform, style, format and note callbacks still receive the original Date.

With "local", the zone is the one of the process writing the file (the TZ environment variable on a server). An IANA name gives the same file on any server, and follows daylight saving time: 2026-03-29 01:30 UTC is 03:30 in Paris.

Excel only accepts dates from 1900-01-01 to 9999-12-31. The range is checked after the conversion.

Copyright © 2026 Cyprien Thao. Released under the MIT License.