PHP - Date & Timestamp Snippets: Unterschied zwischen den Versionen

Aus Wikizone
Wechseln zu: Navigation, Suche
Zeile 14: Zeile 14:
 
</syntaxhighlight>
 
</syntaxhighlight>
 
haven't tested it but should work along these lines
 
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">
 +
<?php
 +
echo '<hr>test WINDOWS server for locales';
 +
 +
/* try different possible locale names for english GB as of PHP 4.3.0 */
 +
echo '<p>';
 +
$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 '<br/>' . 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 '<p>';
 +
$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 '<br/>' . 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 '<p>';
 +
$loc_de = setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'deu_deu');
 +
echo "Preferred locale for german on this system is '$loc_de'";
 +
echo '<br/>' . 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 '<p>';
 +
$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 '<br/>' . 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 '<p>';
 +
$loc_nl = setlocale(LC_ALL, 'nld_nld');
 +
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));
 +
?>
 +
</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.

Version vom 5. Dezember 2018, 18:41 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"> <?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.