PHP - Date & Timestamp Snippets: Unterschied zwischen den Versionen

Aus Wikizone
Wechseln zu: Navigation, Suche
Zeile 19: Zeile 19:
  
 
<syntaxhighlight lang="php">
 
<syntaxhighlight lang="php">
<?php
+
 
 
echo '<hr>test WINDOWS server for locales';
 
echo '<hr>test WINDOWS server for locales';
  
Zeile 51: Zeile 51:
 
echo "Preferred locale for dutch on this system is '$loc_nl'";
 
echo "Preferred locale for dutch on this system is '$loc_nl'";
 
echo '<br/>' . strftime("%A %d %B %Y", mktime(0, 0, 0, 12, 22, 1978));
 
echo '<br/>' . strftime("%A %d %B %Y", mktime(0, 0, 0, 12, 22, 1978));
?>
+
 
 
</syntaxhiglight>
 
</syntaxhiglight>
  
 
It will show you what setlocale setting your server accepts. I had to use "swedish_sweden" on my local xampp server and "sv_SE" on the live server.
 
It will show you what setlocale setting your server accepts. I had to use "swedish_sweden" on my local xampp server and "sv_SE" on the live server.

Version vom 6. Dezember 2018, 13:39 Uhr

Ein paar Beispiele

$today = strtotime(date("Y-m-d"));


Datum (String) in Timestamp umwandeln

For recieving page of today, you would have to create a start and end time range and use them in the selector.

$start = strtotime( date('Y-m-d') . " 00:00:00");
$end = strtotime( date('Y-m-d') . " 23:59:59");

haven't tested it but should work along these lines

Locales Einstellungen auf Windows Server finden

Damit die Monatsnamen in der richtigen Sprache kommen:

<syntaxhighlight lang="php">

echo '


test WINDOWS server for locales';

/* try different possible locale names for english GB as of PHP 4.3.0 */

echo '

'; $loc_en = setlocale(LC_ALL, 'english_gbr', 'english_britain', 'english_england', 'english_great britain', 'english_uk', 'english_united kingdom', 'english_united-kingdom'); echo "Preferred locale for english GB on this system is '$loc_en'"; echo '
' . strftime("%A %d %B %Y", mktime(0, 0, 0, 12, 22, 1978)); /* try different possible locale names for english USA as of PHP 4.3.0 */ echo '

'; $loc_enusa = setlocale(LC_ALL, 'english_usa', 'english_america', 'english_united states', 'english_united-states', 'english_us'); echo "Preferred locale for english USA on this system is '$loc_enusa'"; echo '
' . strftime("%A %d %B %Y", mktime(0, 0, 0, 12, 22, 1978)); /* try different possible locale names for german as of PHP 4.3.0 */ echo '

'; $loc_de = setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'deu_deu'); echo "Preferred locale for german on this system is '$loc_de'"; echo '
' . strftime("%A %d %B %Y", mktime(0, 0, 0, 12, 22, 1978)); /* try different possible locale names for spanish as of PHP 4.3.0 */ echo '

'; $loc_es = setlocale(LC_ALL, 'esp_esp', 'esp_spain', 'spanish_esp', 'spanish_spain'); echo "Preferred locale for spanish on this system is '$loc_es'"; echo '
' . strftime("%A %d %B %Y", mktime(0, 0, 0, 12, 22, 1978)); /* try different possible locale names for dutch as of PHP 4.3.0 */ echo '

'; $loc_nl = setlocale(LC_ALL, 'nld_nld'); echo "Preferred locale for dutch on this system is '$loc_nl'"; echo '
' . strftime("%A %d %B %Y", mktime(0, 0, 0, 12, 22, 1978)); </syntaxhiglight> It will show you what setlocale setting your server accepts. I had to use "swedish_sweden" on my local xampp server and "sv_SE" on the live server.