PHP strptime() function

Example

Parse the time/date generated by strftime():

<?php
$format="%d/%m/%Y %H:%M:%S";
$strf=strftime($format);
echo("$strf");
print_r(strptime($strf,$format));
?>

Definition and Usage

The strptime() function parses the time/date generated by strftime() Generated time/date.

Note:This function is not implemented on the Windows platform.

Syntax

strptime(date,format);
Parameters Description
date Required. The string to be parsed (for example: returned by strftime()).
format

Required. Specifies the format to be used in the date:

  • %a - Abbreviation of the day of the week name
  • %A - Full name of the day of the week
  • %b - Abbreviation of the month name
  • %B - Full name of the month
  • %c - Preferred date and time notation
  • %C - The number representing the century (year divided by 100, ranging from 00 to 99)
  • %d - The day of the month (01 to 31)
  • %D - Time format, the same as the %m/%d/%y notation
  • %e - The day of the month (1 to 31)
  • %g - Similar to %G notation but without the century
  • %G - 4-digit year corresponding to the ISO week number (see %V)
  • %h - Same as %b notation
  • %H - Hour, using 24-hour format (00 to 23)
  • %I - Hour, using 12-hour format (01 to 12)
  • %j - The day of the year (001 to 366)
  • %m - Month (01 to 12)
  • %M - Minutes
  • %n - Newline character
  • %p - am or pm corresponding to the given time value
  • %r - Time notation in a.m. and p.m. format
  • %R - Time notation in 24-hour format
  • %S - Seconds
  • %t - Tab character
  • %T - Current time, the same as the %H:%M:%S notation
  • 蒧umeric representation of the day of the week (1 to 7), Monday[Monday] = 1. Warning: In Sun Solaris systems, Sunday[Sunday] = 1
  • %U - The number of weeks included in the year, starting from the first Sunday of the week as the first day of the first week
  • %V - Number of weeks in the current year according to the ISO 8601 format (01 to 53), where week 1 represents the first week of the current year, which must have at least four days and start with Monday as the first day of the week
  • %W - Number of weeks in the current year, starting from the first Monday as the first week, as the first day of the first week
  • %w - Decimal number representing a day of the week, Sunday[星期日] = 0
  • %x - Preferred date representation without time
  • %X - Preferred time representation without date
  • %y - Year representation that does not include a number representing the century (range from 00 to 99)
  • %Y - Year representation that includes a number representing the century
  • %Z or %z - Time zone name or abbreviation
  • %% - Output a % character

Technical Details

Return Value:

If successful, this function returns an array with the parsed date. If it fails, it returns FALSE.

The meanings of the array keys returned are as follows:

  • [tm_sec] - Seconds in the current minute (0-61)
  • [tm_min] - Minutes in the current hour (0-59)
  • [tm_hour] - Hour of the day since midnight (0-23)
  • [tm_mday] - Day of the month (1-31)
  • [tm_mon] - Number of months passed since January (0-11)
  • [tm_year] - Number of years passed since 1900
  • [tm_wday] - Number of days passed since Sunday (0-6)
  • [tm_yday] - Number of days passed since January 1 of the current year (0-365)
  • [unparsed] - Date could not be parsed by the specified format Identified Parts
PHP Version: 5.1+