0
votes

So, basically I have a client that wants the timezone of his event to be displayed based on the timezone selected for the event e.g

Date: April 20, 2020

Location: Canada, Ontario

Time: 7:00pm

Time Zone: US/Eastern

Displayed as: 7:00pm (GMT) - > this should be equivalent to a shorthand of whatever Time Zone is chosen e.g (EST) and so on - and not the UTC equivalent (UTC-06:00)

I made him select timezones using https://github.com/camroncade/timezone

which uses the string representation of a time zone (US/Eastern)

I have these fields in my database to receive the inputs from my client on creation:

    $table->date('eventdate');
    $table->time('eventdaystarttime');
    $table->time('eventdayendtime');
    $table->string('eventtimezone');

My question is how to get the Shorthand of the Time Zone (eventtimezone) my client selected on creating the event (US/Eastern) and display it as this 7:00 pm (GMT) when outputting it in my blade.view file

1
Why is this "Urgent"?Funk Forty Niner
I am working on the project now, and my deadline is for Tuesday! This is the only part left for me to complete the project.OlaJ
I'm new to Laravel, but could this info possibly help?Paul T.
@PaulT. Thanks for the reference - it helped me find what I needed using momentjs momentjs.OlaJ

1 Answers

0
votes

You can get timezone abbreviations / shorthand with php like this

$date = new DateTime('April 20, 2020');
$date->setTimeZone(new DateTimeZone('US/Eastern'));
echo $date->format('T');

if you save supported timezone as listed on link below you can get them with carbon easily because US/Eastern doesn't work with carbon.

$tz = CarbonTimeZone::create('America/New_York');
echo $tz->getAbbr();

American timezone

https://www.php.net/manual/en/timezones.america.php

Rest of World you can find here

https://www.php.net/manual/en/timezones.php