Format a timestamp in the user's zone

Store UTC. Format with the user's timezone when you send the prop. Do not save local time into a timestamp column.

For your AI agent

Copies a prompt. Paste it into the AI agent you already have open.

Read https://laravel-vuejs.space/laravel-app-timezone-vue.md
Store UTC. Format with the user's timezone when you send the prop. Do not save local time into a timestamp column.
Do not save local time into a timestamp column.
Do not store a local datetime in a timestamp column by formatting it in PHP and writing the string.
Do not trust a timezone name that is not in timezoneidentifierslist().
Show the diff. Do not commit.
On this page · 3 sections
  1. The fix
  2. What to avoid
  3. FAQ

People searching “Laravel timezone Vue” set APP_TIMEZONE to the user’s city and then every row shifts when someone else signs in. config('app.timezone') is the app default. The database connection should store UTC. Convert for display.

TL;DR

  • Store UTC.
  • Format with the user’s timezone when you send the prop.
  • Do not save local time into a timestamp column.
  • Do not store a local datetime in a timestamp column by formatting it in PHP and writing the string.

Who it's for: Laravel + Vue developers

Applies to: Laravel 13 · Vue 3

The fix#

php
$zone = in_array($request->user()->timezone, timezone_identifiers_list(), true)
    ? $request->user()->timezone
    : config('app.timezone');

'createdAt' => $post->created_at->timezone($zone)->toIso8601String(),

The Vue page prints the string. It does not add an offset again. Adding it twice is how a 10:00 post becomes 12:00.

What to avoid#

Gotcha

Do not store a local datetime in a timestamp column by formatting it in PHP and writing the string. The next reader in another zone cannot undo a conversion you did not record. Do not trust a timezone name that is not in timezone_identifiers_list().

FAQ#

How do I format a timestamp in the user's zone?

Store UTC. Format with the user's timezone when you send the prop. Do not save local time into a timestamp column.

What goes wrong with Laravel timezone Vue?

Many developers set APP_TIMEZONE to the user's city and then every row shifts when someone else signs in. Do not store a local datetime in a timestamp column by formatting it in PHP and writing the string.

Found this useful?

Ask questions, share what you built.

Join thousands of Laravel and Vue developers in our Facebook group, or get new posts in your Telegram feed. Sharing this article helps too.

Keep reading

Newsletter

Get the best of Laravel & Vue, once a month.

One short email with new guides, release notes worth reading and hand-picked community links. No spam, unsubscribe any time.