PHP strptime()Functions
PHP Date/Time Reference Manual
Examples
Parse 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 thestrftime()time/date generated by strftime().
Note:This function is not implemented on Windows platforms!
Syntax
| Parameters |
Description |
| date |
Required. The string to parse (e.g., returned by strftime()). |
| format |
Required. Specifies the format to use in the date:
- %a - Abbreviated weekday name
- %A - Full weekday name
- %b - Abbreviated month name
- %B - Full month name
- %c - Preferred date and time representation
- %C - Century number (year divided by 100, range 00 to 99)
- %d - Day of the month (01 to 31)
- %D - Time format, same as %m/%d/%y
- %e - Day of the month (1 to 31)
- %g - Similar to %G, but without the century
- %G - 4-digit year corresponding to the ISO week number (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 - Day of the year (001 to 366)
- %m - Month (01 to 12)
- %M - Minute
- %n - Newline character
- %p - am or pm corresponding to the given time value
- %r - Time notation in a.m. and p.m.
- %R - Time notation in 24-hour format
- %S - Second
- %t - Tab character
- %T - Current time, same as %H:%M:%S
- %u - Numeric representation of the day of the week (1 to 7), Monday = 1. Warning: In Sun Solaris systems, Sunday = 1
- %U - Week number of the current year, starting with the first Sunday as the first day of the first week
- %V - ISO 8601 week number of the current year (01 to 53), where week 1 represents the first week of the year with at least four days, and Monday is the first day of the week
- %W - Week number of the current year, starting with the first Monday as the first day of the first week
- %w - Day of the week as a decimal number, Sunday = 0
- %x - Preferred date representation, without time
- %X - Preferred time representation, without date
- %y - Year without century (range 00 to 99)
- %Y - Year with century
- %Z or %z - Time zone name or abbreviation
- %% - Outputs a % character
|
Technical Details
| Return Value: |
If successful, the function returns an array with the parsed date. If it fails, it returns FALSE. The meanings of the keys in the returned array are as follows:
- [tm_sec] - Seconds within the current minute (0-61)
- [tm_min] - Minutes within the current hour (0-59)
- [tm_hour] - Hours since midnight (0-23)
- [tm_mday] - Day of the month (1-31)
- [tm_mon] - Months since January (0-11)
- [tm_year] - Years since 1900
- [tm_wday] - Days since Sunday (0-6)
- [tm_yday] - Days since January 1 of the current year (0-365)
- [unparsed] - The part of the date that could not be recognized by the specified format
|
| PHP Version: |
5.1+ |
PHP Date/Time Reference Manual Other Extensions