A time zone can change the displayed date.
dotnet add package RecursiveAI.OneEcmaRequires .NET 10 (net10.0); .NET 9 and earlier aren’t supported.
using RecursiveAI.OneEcma; Console.WriteLine(new ScriptEngine() .Evaluate(""" new Intl.DateTimeFormat('de', { timeZone: '-05:00', dateStyle: 'medium', timeStyle: 'short' }).format(new Date("2026-01-01T00:30Z")); """).AsString);
Unzip the example, then dotnet run.
Prints:
31.12.2025, 19:30The full program
using RecursiveAI.OneEcma; var engine = new ScriptEngine(); Console.WriteLine(engine.Evaluate(""" const instant = new Date('2026-01-01T00:30:00Z'); const options = { dateStyle: 'medium', timeStyle: 'short' }; const views = [ ['en-GB', 'UTC'], ['de', '-05:00'], ['en-GB', 'America/New_York'] ]; views.map(([locale, timeZone]) => { const formatter = new Intl.DateTimeFormat(locale, { ...options, timeZone }); return `${locale} / ${formatter.resolvedOptions().timeZone}: ${formatter.format(instant)}`; }).join('\n'); """).AsString);
dotnet run prints:
en-GB / UTC: 1 Jan 2026, 00:30 de / -05:00: 31.12.2025, 19:30 en-GB / America/New_York: 31 Dec 2025, 19:30
UTC and fixed offsets like -05:00 work without host time-zone data. Named zones like America/New_York use the host’s rules. An unknown zone raises JavaScript RangeError.
Variations
Use formatToParts when you need a field rather than a display string. Replace the JavaScript inside Evaluate with the code below. It prints Januar.
const instant = new Date('2026-01-01T00:30Z'); const formatter = new Intl.DateTimeFormat('de', { month: 'long', timeZone: 'UTC' }); formatter.formatToParts(instant) .find(part => part.type === 'month').value;
Related recipes
- Sort JavaScript strings by locale in C#
- Split JavaScript text into graphemes in C#
- Normalize JavaScript Unicode text in C#
The short answer
Construct Intl.DateTimeFormat with a locale and a timeZone, then call .format() on a JavaScript Date inside OneEcma. The full program passes the same instant to each formatter. At 00:30 on January 1 in UTC, a zone five hours behind UTC still shows December 31, and German formatting writes the day and month numerically in this example.
What does the timeZone option do in Intl.DateTimeFormat?
It determines the local date and time shown for the instant. A Date contains a time value, not a display locale or a named zone. Changing the formatter doesn’t move the instant. The Z in the ISO timestamp denotes UTC; the output zone is a separate choice. Use an input with an explicit offset when you already know the instant. For a calendar invitation, keep that instant and format it for each recipient instead of reinterpreting a display string as input. The MDN constructor reference describes the distinction between zone and formatting options.
Which time zones can you use with Intl.DateTimeFormat?
You can request UTC, a fixed numeric offset such as -05:00, or a named zone supported by your host. A fixed offset never switches for daylight saving; use a name such as America/New_York when you want local clock rules across seasons. For names, OneEcma’s Intl documentation says “the host supplies the rules.” A deployment whose host can’t resolve your zone needs a zone source or a deliberate choice of UTC, not a guess at the offset. If you omit timeZone, OneEcma uses IJsHost.TimeZoneId; the default host uses UTC. resolvedOptions().timeZone, shown in the full program, reports the resolved identifier, not the offset at your instant.
Which calendars and locales can OneEcma format?
The embedded data supports en-US, en-GB, es (and es-US), fr, de, and pt-BR. OneEcma’s Intl documentation specifies “Gregorian calendar and Latin digits; any other calendar or numberingSystem falls back to them.” An unsupported locale also falls back to the host default if you haven’t given another supported locale in the preference list. For a localized display, choose dateStyle and timeStyle as in the main example, or individual fields as in the variation. Don’t mix styles with field options such as month; that raises TypeError. Keep the display string for humans; for a field you’ll render separately, use the parts rather than splitting on punctuation.