gmstrftime

(PHP 4, PHP 5, PHP 7, PHP 8)

gmstrftimeFormata uma data/hora GMT/UTC de acordo com as configurações de localidade

Aviso

Esta função tornou-se DEFASADA a partir do PHP 8.1.0. O uso desta função é fortemente desencorajado.

Alternativas a esta função incluem:

Descrição

gmstrftime(string $format, ?int $timestamp = null): string|false

Possui o mesmo comportamento que a função strftime() exceto que o tempo retornado será no Horário de Greenwich (GMT). Por exemplo, quando executada no fuso horário EST (GMT -0500), a primeira linha abaixo imprime "Dec 31 1998 20:00:00", enquanto a segunda linha imprime "Jan 01 1999 01:00:00".

Aviso

Esta função depende das informações de localidade do sistema operacional, que podem ser inconsistentes ou não disponíveis. Ao invés disso, use o método IntlDateFormatter::format().

Parâmetros

format

Veja a descrição em strftime().

timestamp

O parâmetro opcional timestamp é um int de timestamp Unix cujo padrão é a hora local atual se timestamp não for informado ou for null. Em outras palavras, o padrão é o valor de time().

Valor Retornado

Retorna uma string formatada de acordo com a string de formatação, usando o timestamp informado, ou o horário local se nenhum timestamp é informado. Nomes de meses, dias da semana e outras strings que dependem do idioma respeitam a configuração de localidade atual definido com a função setlocale(). Em caso de falha, é retornado false.

Registro de Alterações

Versão Descrição
8.0.0 timestamp agora pode ser nulo.

Exemplos

Exemplo #1 Exemplo da função gmstrftime()

<?php
setlocale
(LC_TIME, 'en_US');
echo
strftime("%b %d %Y %H:%M:%S", mktime(20, 0, 0, 12, 31, 98)) . "\n";
echo
gmstrftime("%b %d %Y %H:%M:%S", mktime(20, 0, 0, 12, 31, 98)) . "\n";
?>

Veja Também

add a note add a note

User Contributed Notes 4 notes

up
1
yellow dot snow at huskies dot com
19 years ago
HTTP 1.1 (RFC 2068) requires an RFC 1123 date with a four digit year, so the correct format to use for a Last-modified header would look something like this:

<?php
header
("Last-modified: " .
gmstrftime("%a, %d %b %Y %T %Z",getlastmod()));
?>
up
1
pvdster at hotmail dot com
18 years ago
If you want the dutch time on your pages and you are hosted on a server in the USA you can easily change it this way:

<?php
setlocale
(LC_TIME, 'nl_NL');
$tgl = gmstrftime("%d %B %Y - %H:%M uur",time()+3600);
?>

Then use $tgl to display the right time.
Note the +3600 is a day light savings time correction.
The result: 22 maart 2005 - 16:39 uur

First I used the normal date function and this was the previous result: March 22, 2005 - 04:28 AM

I needed it for a dutch guestbook.

I'm new to PHP and it took me a while to find it out and maybe it's of no use for experienced PHP programmers but I thought people can always ignore my post :)
up
-2
neo at gothic-chat d0t de
19 years ago
To get a RFC 850 date (used in HTTP) of the current time:

gmstrftime ("%A %d-%b-%y %T %Z", time ());

This will get for example:
Friday 25-Jun-04 03:30:23 GMT

Please note that times in HTTP-headers _must_ be GMT, so use gmstrftime() instead of strftime().
up
-3
peter dot albertsson at spray dot se
19 years ago
gmstrftime() should not be used to generate a RFC 850 date for use in HTTP headers, since its output is affected by setlocale().

Use gmdate instead:

gmdate('D, d M Y H:i:s') . ' GMT';
To Top