# Set the system time in Bun's test runner (/docs/guides/test/mock-clock)

<!-- agent-signals: reading_time_min: 1 · est_tokens: 260 · updated: 2026-07-28 -->
Related: [Run your tests with the Bun test runner](/docs/guides/test/run-tests.md), [Run tests in watch mode with Bun](/docs/guides/test/watch-mode.md), [Migrate from Jest to Bun's test runner](/docs/guides/test/migrate-from-jest.md), [Mock functions in `bun test`](/docs/guides/test/mock-functions.md), [Spy on methods in `bun test`](/docs/guides/test/spy-on.md), [Use snapshot testing in `bun test`](/docs/guides/test/snapshot.md)

Set the system time in tests with the `setSystemTime` function from `bun:test`.

```ts
import { test, expect, setSystemTime } from "bun:test";

test("party like it's 1999", () => {
  const date = new Date("1999-01-01T00:00:00.000Z");
  setSystemTime(date); // it's now January 1, 1999

  const now = new Date();
  expect(now.getFullYear()).toBe(1999);
  expect(now.getMonth()).toBe(0);
  expect(now.getDate()).toBe(1);
});
```

***

Call `setSystemTime` in a [lifecycle hook](/test/lifecycle) like `beforeAll` to give your tests a deterministic "fake clock".

```ts
import { test, expect, beforeAll, setSystemTime } from "bun:test";

beforeAll(() => {
  const date = new Date("1999-01-01T00:00:00.000Z");
  setSystemTime(date); // it's now January 1, 1999
});

// tests...
```

***

To reset the system clock to the actual time, call `setSystemTime` with no arguments.

```ts
import { test, expect, beforeAll, setSystemTime } from "bun:test";

setSystemTime(); // reset to actual time
```

***

See [Dates and times](/test/dates-times).
