strptime() function in PHP

WBOY
Release: 2023-08-20 09:14:01
forward
933 people have browsed it

strptime() function in PHP

The strptime() function parses the time/date generated using strftime(). This function returns a parsed date array, or FALSE if an error occurs. The following parameters will be returned in an array.

  • [tm_sec] − Seconds (0-61)

  • [tm_min] − Minutes (0-59)

  • [tm_hour] − hour (0-23)

  • [tm_mday] − day of month (1-31)

  • [tm_mon] − Number of months since January (0-11)

  • [tm_year] − Number of years since 1900

  • [tm_wday] − Number of days since Sunday (0-6)

  • [tm_yday] − Number of days since January 1 (0-365)

  • [unparsed] − Use the unrecognized date part (if any) of the specified format

Syntax

strptime(date, format)
Copy after login

Parameters

  • date − The string to parse

  • format − The format of the date and use the following Format as −

    • %a − abbreviated day of the week name

    • ##%A − full day of the week name

    • %b − abbreviated month name

    • %B − full month name

    • %c − preferred Date and time representation

    • %C − Century (year divided by 100, range 00 to 99)

    • %d − Month date (01 to 31)

    • %D − Same as %m/%d/%y

    • %e − Day in the month (1 to 31)

    • %g − Similar to %G, but does not include the century

    • %G − Corresponds to the ISO week number 4-digit year (see %V)

    • %h − Same as %b

    • ##%H − Hour, using 24-hour format (00 to 23)
    • %I − hour, using 12-hour format (01 to 12)
    • %j − number of days in year (001 to 12) 366)
    • %m − Month (01 to 12)
    • %M − Minute
    • %n − Line break
    • %p − AM or PM depending on the given time value
    • %r − AM and PM representation Time
    • ##%R − Time in 24-hour format
    • %S − Seconds
    • %t − Tab character
    • %T − Current time, equivalent to %H:%M:%S
    • %u − Day of the week A few are numbers (1 to 7), Monday is 1. Warning: Sunday is 1
    • %U in Sun Solaris - the number of weeks in the year, starting with the first Sunday as the first day of the first week
    • %V − ISO 8601 week number (01 to 53) in the current year, where week 1 has at least 4 days in the current year and Monday is the first day of the week
    • %W − The number of weeks in the current year, starting from the first Monday as the first day of the first week
    • %w − The number of the day of the week, Sunday is 0
    • ##%x − Preferred date representation, excluding time

    • ##%X − Preferred time representation, excluding date

    • %y − The year does not include the century (range is 00 to 99)

    • %Y − The year includes the century

    • %Z or %z − time zone or name or abbreviation

    • %% − literal % character

    • Return value
    strptime() function returns an array, or returns FALSE on failure.
Example

The following is an example −

Live Demo

<?php
   $format = &#39;%d/%m/%Y %H:%M:%S&#39;;
   $strf = strftime($format);
   echo "$strf</p><p>";
   print_r(strptime($strf, $format));
?>
Copy after login

Output

The following is the output −

11/10/2018 05:18:13
Array
(
   [tm_sec] => 13
   [tm_min] => 18
   [tm_hour] => 5
   [tm_mday] => 11
   [tm_mon] => 9
   [tm_year] => 118
   [tm_wday] => 4
   [tm_yday] => 283
   [unparsed] =>
)
Copy after login

The above is the detailed content of strptime() function in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!