---
title: "Format JavaScript dates by locale and time zone in C#"
url: https://recursiveai.org/oneecma/cookbook/format-javascript-dates-by-locale/
description: "Use Intl.DateTimeFormat in C# to display one JavaScript instant in two locales and time zones. Learn which calendars and zone rules OneEcma supports."
version: "1.1.1"
---

# Format JavaScript dates by locale and time zone in C#

**OneEcma** is a free, open-source JavaScript interpreter for .NET from Recursive AI. MIT or Apache-2.0, no native dependencies.

[NuGet](https://www.nuget.org/packages/RecursiveAI.OneEcma) · [GitHub](https://github.com/recursive-ai-oss/oneecma-csharp) · [Docs](https://recursiveai.org/oneecma/docs/) · [Download example (.zip)](https://recursiveai.org/oneecma/cookbook/format-javascript-dates-by-locale/format-javascript-dates-by-locale.zip)

A time zone can change the displayed date.

```shell
dotnet add package RecursiveAI.OneEcma
```

Requires [.NET 10](https://dotnet.microsoft.com/download/dotnet/10.0) (net10.0); .NET 9 and earlier aren’t supported.

```csharp
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](https://recursiveai.org/oneecma/cookbook/format-javascript-dates-by-locale/format-javascript-dates-by-locale.zip), then `dotnet run`.

Prints:

```text
31.12.2025, 19:30
```

## The full program

```csharp
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:

```text
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`.

```javascript
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#](https://recursiveai.org/oneecma/cookbook/sort-javascript-strings-with-locale-collation/)
- [Split JavaScript text into graphemes in C#](https://recursiveai.org/oneecma/cookbook/segment-javascript-text-into-graphemes/)
- [Normalize JavaScript Unicode text in C#](https://recursiveai.org/oneecma/cookbook/normalize-javascript-unicode-text/)

## 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](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat) 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](https://recursiveai.org/oneecma/docs/intl/#time-zone-source) 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](https://recursiveai.org/oneecma/docs/intl/#datetimeformat) 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.
