IntlCalendar::clear

(PHP 5 >= 5.5.0, PHP 7, PHP 8, PECL >= 3.0.0a1)

IntlCalendar::clearClear a field or all fields

Beschreibung

Objektorientierter Stil

public IntlCalendar::clear(?int $field = null): bool

Prozeduraler Stil

intlcal_clear(IntlCalendar $calendar, ?int $field = null): bool

Clears either all of the fields or a specific field. A cleared field is marked as unset, giving it the lowest priority against overlapping fields or even default values when calculating the time. Additionally, its value is set to 0, though given the fieldʼs low priority, its value may have been internally set to another value by the time the field has finished been queried.

Parameter-Liste

calendar

Eine IntlCalendar-Instanz.

field

One of the IntlCalendar date/time field constants. These are integer values between 0 and IntlCalendar::FIELD_COUNT.

Rückgabewerte

Gibt immer true zurück.

Beispiele

Beispiel #1 IntlCalendar::clear() examples

<?php
ini_set
('intl.default_locale''es_ES');
ini_set('date.timezone''UTC');

$fields = array(
    
'FIELD_ERA'                  => 0,
    
'FIELD_YEAR'                 => 1,
    
'FIELD_MONTH'                => 2,
    
'FIELD_WEEK_OF_YEAR'         => 3,
    
'FIELD_WEEK_OF_MONTH'        => 4,
    
'FIELD_DATE'                 => 5,
    
'FIELD_DAY_OF_YEAR'          => 6,
    
'FIELD_DAY_OF_WEEK'          => 7,
    
'FIELD_DAY_OF_WEEK_IN_MONTH' => 8,
    
'FIELD_AM_PM'                => 9,
    
'FIELD_HOUR'                 => 10,
    
'FIELD_HOUR_OF_DAY'          => 11,
    
'FIELD_MINUTE'               => 12,
    
'FIELD_SECOND'               => 13,
    
'FIELD_MILLISECOND'          => 14,
    
'FIELD_ZONE_OFFSET'          => 15,
    
'FIELD_DST_OFFSET'           => 16,
    
'FIELD_YEAR_WOY'             => 17,
    
'FIELD_DOW_LOCAL'            => 18,
    
'FIELD_EXTENDED_YEAR'        => 19,
    
'FIELD_JULIAN_DAY'           => 20,
    
'FIELD_MILLISECONDS_IN_DAY'  => 21,
    
'FIELD_IS_LEAP_MONTH'        => 22,
    
'FIELD_FIELD_COUNT'          => 23,
);
function 
getSetFields(IntlCalendar $cal) {
    global 
$fields;
    
$ret = array();
    foreach (
$fields as $name => $value) {
        if (
$cal->isSet($value)) {
            
$ret[] = $name;
        }
    }
    return 
$ret;
}

$cal = new IntlGregorianCalendar(2013/* March */15);
echo 
"After GregorianCalendar creation\n";
print_r(getSetFields($cal));
echo 
"\n";

echo 
IntlDateFormatter::formatObject($cal), "\n";
echo 
"After the formatter requested the extended year\n";
print_r(getSetFields($cal));
echo 
"\n";

$cal->clear(IntlCalendar::FIELD_YEAR);
echo 
"After the year has been cleared, the date stays the same\n";
echo 
IntlDateFormatter::formatObject($cal), "\n";
echo 
"because FIELD_EXTENDED_YEAR is still set\n";
print_r(getSetFields($cal));
echo 
"\n";

var_dump($cal->clear(IntlCalendar::FIELD_EXTENDED_YEAR));
echo 
"After the extended year has been cleared\n";
print_r(getSetFields($cal));
echo 
IntlDateFormatter::formatObject($cal), "\n";
echo 
"\n";

echo 
"After the fields are recalculated,\n"
        
" extended year is set again (to 1970)\n";
print_r(getSetFields($cal));
echo 
"\n";

$cal->clear();
echo 
"After calling variant with no arguments\n";
print_r(getSetFields($cal));
echo 
IntlDateFormatter::formatObject($cal), "\n";

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

After GregorianCalendar creation
Array
(
    [0] => FIELD_ERA
    [1] => FIELD_YEAR
    [2] => FIELD_MONTH
    [3] => FIELD_DATE
)

15/03/2013 00:00:00
After the formatter requested the extended year
Array
(
    [0] => FIELD_ERA
    [1] => FIELD_YEAR
    [2] => FIELD_MONTH
    [3] => FIELD_DATE
    [4] => FIELD_EXTENDED_YEAR
)

After the year has been cleared, the date stays the same
15/03/2013 00:00:00
because FIELD_EXTENDED_YEAR is still set
Array
(
    [0] => FIELD_ERA
    [1] => FIELD_MONTH
    [2] => FIELD_DATE
    [3] => FIELD_EXTENDED_YEAR
)

bool(true)
After the extended year has been cleared
Array
(
    [0] => FIELD_ERA
    [1] => FIELD_MONTH
    [2] => FIELD_DATE
)
15/03/1970 00:00:00

After the fields are recalculated,
 extended year is set again (to 1970)
Array
(
    [0] => FIELD_ERA
    [1] => FIELD_MONTH
    [2] => FIELD_DATE
    [3] => FIELD_EXTENDED_YEAR
)

After calling variant with no arguments
Array
(
)
01/01/1970 00:00:00

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Grundlagen von Views in MySQL

Views in einer MySQL-Datenbank bieten die Möglichkeit, eine virtuelle Tabelle basierend auf dem Ergebnis einer SQL-Abfrage zu erstellen. ...

admin

Autor : admin
Kategorie: mySQL-Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

Daten einer Abfrage mit Hilfe von Thumbnails nebeneinander ausgeben

Warum soll ich float meiden? Siehe https://www.linkedin.com/pulse/css-float-vs-grid-flexbox-sachin-tiwari Falls es mit Englisch nicht so klappt: ...

Geschrieben von scatello am 18.05.2024 05:57:56
Forum: PHP Developer Forum
Daten einer Abfrage mit Hilfe von Thumbnails nebeneinander ausgeben

Also den Fehler habe ich gefunden und abgestellt. Warum soll ich float meiden?

Geschrieben von Malchor am 17.05.2024 20:54:01
Forum: PHP Developer Forum
Daten einer Abfrage mit Hilfe von Thumbnails nebeneinander ausgeben

Dein HTML-Code ist definitiv kaputt und float solltest du auch vergessen. Beschäftige dich mit Flex-Box oder Grid

Geschrieben von scatello am 17.05.2024 20:43:50
Forum: PHP Developer Forum
Daten einer Abfrage mit Hilfe von Thumbnails nebeneinander ausgeben

Da ich viele unterschiedliche Tabellen benötige mache ich das so umständlich. Aber ist das der Grund warum das Floaten nicht funktioniert?

Geschrieben von Malchor am 17.05.2024 17:15:03
Forum: PHP Developer Forum