Site icon sharedsapience.info

PHP Date/Time Function Quiz 3: DateTime::setTimestamp(); DateTime::getTimezone(); DateTime::setTimezone(); date(); getdate(); gettimeofday(); gmdate(); gmmktime(); gmstrftime(); idate(); and localtime().

First three rows of the PHP DateTime Mini Quiz 3, sized for desktop viewing.

An image of the first three rows of the PHP DateTime Mini Quiz 3, sized for desktop viewing.

HOW THE QUIZ WORKS:

Clicking the ‘randomize’ button situated above the reference table generates a new table whereby the function descriptions, function syntaxes, and function return values are randomized. The quiz involves matching the function descriptions, function syntaxes, and function return values to the correct function name. Information relating to the randomization of table cells will be displayed for three seconds, before disappearing.

On a desktop computer, table elements are selected by left-clicking the desired table cell and holding the left click in the mouse down position for one second before releasing the left click. The text inside the table cell will turn red to indicate that the one-second mouse left-click has successfully selected a table cell. To then swap the selected table cell with the target table cell, simply repeat the one-second left mouse-click process on the target cell; the table cells will swap position. To de-select a table cell, simply repeat the one-second left mouse-click process on the original table cell.

To select a table element on a touchscreen device (mobile, tablet), simply touch the desired table cell and maintain the touch for one second before removing your finger from the screen. The text inside the table cell will turn red to indicate that the one-second touch has successfully selected a table cell. To then swap the selected table cell with the target table cell, simply repeat the one-second touch process on the target cell; the table cells will swap position. To de-select a table cell, simply repeat the one-second touch process on the original table cell.

Normal touchscreen scrolling behaviour is exhibited by the cells with a light green background; cells without a light green background will not respond to normal touchscreen scrolling. The table is positioned in such a way that the user can also initiate touchscreen scrolling by swiping to the right or left of the table.

When a row consists of the correct function name, function description, function syntax, and function return value, the background colour of the row will change from ‘transparent’ to ‘khaki’; this provides visual feedback that the row is complete.

Once the entire table is complete, a paragraph of feedback will congratulate the user and provide the following information: date and time of quiz commencement; date and time of quiz completion; and the length of time it took the user to complete the quiz.

VIEWPORT OPTIONS:

An example of the layout designed for mobile phones
An example of the layout designed for tablets
An example of the layout designed for desktop computers

PURPOSE:

This webpage serves two purposes:

  1. It provides a reference table for the PHP date/time functions, with information extracted and condensed from w3schools.com and php.net.
  2. It enables users to complete a quiz related to the PHP date/time functions.

USAGE:

For each date/time function there are four table cells of information: the function name; the function description; the function syntax; and the function return value. There are three layouts available – ‘mobile‘, ‘tablet‘, and ‘desktop‘.

Click the relevant button below to display the PHP date/time functions reference table, sized appropriately for the desired viewport. A ‘RANDOMIZE‘ button appears above the reference table once the viewport is selected; clicking this button facilitates the commencement of a quiz.



Click the ‘RANDOMIZE‘ button to randomize the functional descriptions, the functional syntaxes, and the functional return information.



FUNCTION NAME FUNCTION DESCRIPTION FUNCTION SYNTAX FUNCTION RETURN VALUE
DateTime::setTimestamp()
date_timestamp_set()

[Sets the date and time based on an Unix timestamp]

Sets the date and time based on a Unix timestamp. Object-oriented style:
DateTime::setTimestamp(unix_timestamp);
Procedural style:
date_timestamp_set(datetime_object, unix_timestamp);
DateTime::setTimestamp(): returns the DateTime object for method chaining on success; FALSE on failure.
DateTime::getTimezone()
date_timezone_get()

[Return time zone relative to given DateTime]

Returns the time zone relative to the given DateTime. Object-oriented style:
DateTime::getTimezone();
Procedural style:
date_timezone_get(DateTimeInterface_object);
Returns a DateTimeInterface object on success; FALSE on failure.
DateTime::setTimezone()
date_timezone_set()

[Sets the time zone for the DateTime object]

Sets the time zone for the DateTime object. Object-oriented style:
DateTime::setTimezone(timezone);
Procedural style:
date_timezone_set(DateTime_object, timezone);
DateTime::setTimezone(): returns the DateTime object for method chaining on success; FALSE on failure.
date()

[Format a local time/date]

Returns a date string formatted according to the given format string, using the provided timestamp or the current time if no timestamp is given. The optional timestamp defaults to the value of time(). date(format, timestamp [optional parameter]);

[formatting options: d [day: 01 — 31]; D [3-letter day representation: Mon — Sun]; j [day: 1 — 31]; l [day: Monday — Sunday]; N [ISO-8601 day representation: 1 (Monday) — 7 (Sunday)]; S [st, nd, rd, th]; w [0 (Sunday) — 6 (Saturday)]; z [Day of year: 0 — 365]; W [ISO-8601 week number of year, starting on Monday]; F [full month name: January — December]; m [numerical month representation: 01 — 12]; M [month name: jan — dec]; n [numerical month representation: 1 -12]; t [number of days in given month: 28 – 31]; L [uppercase ‘l’ — leap year?1:0]; o [ISO-8601 week-numbering year; same value as Y except that if W belongs to the previous or next year, that year is used instead — 1999, 2003]; Y [4-digit year representation — 1999, 2003]; y [2-digit year representation — 99, 03]; a [lowercase Ante meridiem and Post meridiem]; A [uppercase Ante meridiem and Post meridiem]; B [Swatch Internet time — 000 – 999]; g [12-hour time format: 1 — 12]; G [24-hour time format: 0 — 23]; h [12-hour time format: 01 – 12]; H [24-hour time format: 00 – 23]; i [minutes — 00 – 59]; s [seconds – 00 – 59]; u [microseconds: date() will always generate 000000, whereas DateTime::format() does support microseconds if DateTime is instantiated with microseconds — 654321]; v [milliseconds: same rules apply as for u — 654]; e [timezone identifier: UTC, GMT, Atlantic/Azores]; I [uppercase ‘i’ — Daylight Savings Time?1:0]; O [difference to GMT in hours — +0200]; P [difference to GMT in ‘hours:mins’ format — +02:00]; T [timezone abbreviation: EST, MDT]; Z [timezone offset from UTC in seconds; timezones west of UTC are always negative, timezones east of UTC are always positive: -43200 — 50400]; c [ISO-8601 date: 2004-02-12T15:19:21+00:00]; r [RFC 2822-formatted date: Thu, 21 Dec 2000 16:01:07 +0200]; and U [seconds since the Unix Epoch (January 1 1970 00:00:00 GMT)].
Unrecognised characters will be printed as-is. ]

Returns a formatted date string. If a non-numeric value is used for timestamp, FALSE is returned and an E_WARNING level error is emitted.
getdate()

[Get date/time information]

Returns an associative array containing the date information of timestamp or the current local time if timestamp is not provided. getdate(timestamp [optional parameter defaulting to value of time()]); Returns an associative array containing date information relating to timestamp. Elements comprise: ‘seconds’ [0-59]; ‘minutes’ [0-59]; ‘hours’ [0-23]; ‘mday’ [1-31]; ‘wday’ [0 (Sunday) – 6 (Saturday)]; ‘mon’ [1-12]; ‘year’ [1999, 2003]; ‘yday’ [0-365]; ‘weekday’ [Sunday — Saturday]; ‘month’ [January — December]; ‘0’ [seconds since the Unix Epoch: system-dependent, typically from -2147483648 — 2147483647].
gettimeofday()

[Get current time]

An interface call to gettimeofday(2); it returns the time of day information-related associative array returned from the system call. gettimeofday(return_float [optional boolean parameter – if ‘true’ then a float is returned instead of an associative array]); If return_float is true then a float is returned. Otherwise, an associative array is returned, comprising the following time of day elements: ‘secs’ [seconds since the Unix Epoch]; ‘usec’ [microseconds]; ‘minuteswest’ [minutes west of Greenwich]; and ‘dsttime’ [type of dst correction].
gmdate()

[Format a GMT/UTC date/time]

Identical to the date() function, except that the time returned is GMT. gmdate(format, timestamp [optional parameter, defaulting to value of time()]);

[The valid range of timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT.]

gmdate(): returns a formatted date string. If a non-numeric value is used for timestamp, FALSE is returned and an E_WARNING level error is emitted.
gmmktime()

[Get Unix timestamp for a GMT date]

Identical to mktime() except that the passed parameters represents a GMT date. Returns the Unix timestamp for the created date. gmmktime(hour, minute, second, month, day, year, is_dst);

[All parameters above are optional. Defaults: hourgmdate("H"); minutegmdate("i"); secondgmdate("s"); monthgmdate("n"); daygmdate("j"); yeargmdate("Y"); is_dst = -1.]

gmmktime(): returns an integer Unix timestamp.
gmstrftime()

[Format a UTC/GMT time/date according to locale settings]

Behaves the same as strftime() except that the formatted time string returned is GMT. gmstrftime(format, timestamp [optional parameter, defaulting to the value of time()]); gmstrftime(): returns a string formatted according to the given format using timestamp if given, or the value of time(). Month and weekday names and other language-dependent strings respect the current locale set with setlocale().
idate()

[Format a local time/date as integer]

Returns a number formatted according to format using the timestamp parameter if present, or the current local time() if not. idate() accepts just one char in the format parameter. idate(format, timestamp [optional parameter]);

[The following characters can be used as the format string: B; d; h; H; i; I; l; m; s; t; U; w; W; y; Y; z; and Z. Please cross-reference the format codes used in the date() function, detailed above.]

Always returns an integer. Since integers cannot start with 0, this function may return fewer digits than initially expected. Every call to a date/time function will generate an E_NOTICE if the timezone is not valid, and/or a E_STRICT or E_WARNING message if using the system settings or the TZ environment variable.
localtime()

[Get the local time]

Returns an array of local time-related elements. If is_associative is set to true, the associative array contains all the different elements of the structure returned by the C function call to localtime. The different keys of the associative array are: ‘tm_sec’ (0 — 59); ‘tm_min’ (0 — 59); ‘tm_hour’ (0 — 23); ‘tm_mday’ (1 — 31); ‘tm_mon’ (0 [Jan] — 11 [Dec]); ‘tm_year’ (years since 1900); ‘tm_wday’ (0 [Sun] — 6 [Sat]); ‘tm_yday’ (0 — 365); ‘isdst’ (?1:0:-) [DST? positive if yes:0 if no:negative if unknown]. localtime(timestamp [optional parameter, defaulting to value of time()], is_associative [optional parameter, with a default value of false]);. If is_associative is set to false or not provided, a numerically-indexed array is returned. If is_associative is set to true, an associative array is returned.

Web design certified by:
Click images for proof of certification.

Exit mobile version