Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

335
Visualizações
Converting a Time from a database to BST with PHP

So I've trying all sorts of combinations to get a date from my database (using Wordpress) to display in British Summer Time and I cannot get anything to work.

Is there any simple solution that can take the date string and make sure that in Summer Time in the UK it's an hour on from UTC time?

$classJson = $class->info;
$classJsonAsArray = json_decode($classJson, TRUE);

$classStartDate = strtotime($class->periodStart);
$classStartTime = date('H:i',$classStartDate);

So currently $class->periodStart returns: 2022-04-06 08:30:00

The time of that event should be 9.30am

All I need it to do is display the correct time, as at the moment, on the front end it displays as 8.30am.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

DateTime handles timezones quite well.

$dateStringInUtc = '2022-04-06 08:30:00';
$date = new DateTime($dateStringInUtc, new DateTimeZone('UTC'));
$date->setTimezone(new DateTimeZone('Europe/London'));

echo $date->format('Y-m-d H:i:s'); // will output 2022-04-06 09:30:00
over 4 years ago · Santiago Trujillo Relatório

0

Working with DateTime and timezones like in the accepted answer is the better way.

But it also works with strtotime if the timezone is appended to the date string. Date then returns the local time for a timestamp.

$utcDate = '2022-04-06 08:30:00';
echo date('Y-m-d H:i:s',strtotime($utcDate.' UTC'));
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda