Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

CrastyCrap's avatar

Change server date to local date

how to display created_at of instance in user local time i mean the date by default saved in UTC time zone i want if someone at EST timezone or any other time zone to display date in his time not utc time

0 likes
5 replies
tisuchi's avatar

@crastycrap That's what I can think of.

use Carbon\Carbon;

$userTimezone = 'Europe/Berlin'; 
$createdAt = Carbon::parse($instance->created_at)->setTimezone($userTimezone);

echo $createdAt;
CrastyCrap's avatar

@tisuchi the problem here that if will be fixed time and i need to be dynamic i mean if user in berlin i want date to converted to berline time if user in USA est i want time dynamically convert to this region time

tisuchi's avatar

@CrastyCrap Yes, that's what exactly I mean.

Here $userTimezone is set by the user based on the timezone.

However since you have fixed by the front-end, this will be literally the same.

CrastyCrap's avatar
CrastyCrap
OP
Best Answer
Level 5

i add the timezone in input like the following

<input type="text" vaue=value="{{ $story->created_at }} UTC"> 

and convert it by JS

GoWin_Mehra's avatar

it can be possible if you are able to take user country preference. I hope it will work

Please or to participate in this conversation.