PHP - Date & Timestamp Snippets: Unterschied zwischen den Versionen
Aus Wikizone
Steff (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „ 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. <syntaxh…“) |
Steff (Diskussion | Beiträge) |
||
| (4 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
| Zeile 1: | Zeile 1: | ||
| + | == Ein paar Beispiele == | ||
| + | <syntaxhighlight lang="php"> | ||
| + | $today = strtotime(date("Y-m-d")); | ||
| + | </syntaxhighlight> | ||
| + | |||
| − | Datum (String) in Timestamp umwandeln | + | ==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. | For recieving page of today, you would have to create a start and end time range and use them in the selector. | ||
| + | |||
<syntaxhighlight lang="php"> | <syntaxhighlight lang="php"> | ||
$start = strtotime( date('Y-m-d') . " 00:00:00"); | $start = strtotime( date('Y-m-d') . " 00:00:00"); | ||
$end = strtotime( date('Y-m-d') . " 23:59:59"); | $end = strtotime( date('Y-m-d') . " 23:59:59"); | ||
| − | </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"> | ||
| + | |||
| + | 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)); | ||
| + | |||
| + | </syntaxhighlight> | ||
| + | |||
| + | 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. | ||
Aktuelle Version vom 6. Dezember 2018, 13:39 Uhr
Ein paar Beispiele[Bearbeiten]
$today = strtotime(date("Y-m-d"));
Datum (String) in Timestamp umwandeln[Bearbeiten]
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[Bearbeiten]
Damit die Monatsnamen in der richtigen Sprache kommen:
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));
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.