php.js : strptime() function

strptime() function

The strptime() function is used to parse a time/date generated with strftime() and returns an array.




strptime(str_date, format ) 


Name Description Required /
format Day :
%a - Short day abbreviation ( Sun through Sat)
%A - A full day name ( Sunday through Saturday)
%d - Numeric day of the month with leading zeros (01 to 31)
%e - Day of the month without leading zeros (1 to 31 )
%j - Day of the year, 3 digits with leading zeros (001 to 366)
%u - ISO-8601 numeric day of the week 1 (for Monday) through 7 (for Sunday)
%w - Numeric day of the week 0 (for Sunday) through 6 (for Saturday)

Week :
%U - Week number of a specified year, starting with the first Sunday as the first week 13 (for the 13th full week of the year)
%V - ISO-8601:1988 week number of a specific year, starting the first week of the year with at least 4 weekdays. Example : Monday being the start of the week 01 through 53
%W - Numeric representation of week number of year. Week starting from Monday

Month :
%b - Abbreviated month name (Jan through Dec)
%B - Full month name (January through December)
%h - Abbreviated month name (Jan through Dec)
%m - Numeric representation of the month in two digits 01 (for January) through 12 (for December)

Year :
%C - Numeric representation of the century in two digits
%g - Two digit representation of the year going by ISO-8601:1988 standards
%G - The full four-digit representation of the year
%y - Numeric representation of the year in two digits (Example: 99 for 1999)
%Y - Four digit representation for the year Example: 2011

Time :

%H - 24-hour format of an hour (00 through 23)
%I - 12-hour format of an hour (01 through 12 )
%l - 12-hour format of an hour without leading zeros (1 to 12)
%M -Minutes with leading zeros (00 through 59)
%p - UPPER-CASE 'AM' or 'PM'
%P - lower-case 'am' or 'pm'
%r - Same as "%I:%M:%S %p"
%R - Same as "%H:%M"
%S - Seconds with leading zero (00 through 59)
%T - Same as "%H:%M:%S"
%X - Represent times without the date
%z - The time zone offset from UTC or the abbreviation
%Z - The time zone offset or abbreviation if option NOT given by %z

Time and Date Stamps :
%c - A specific date and time stamp based on local
%D - Same as "%m/%d/%y"
%F - Same as "%Y-%m-%d" (usually used in database datestamps)
%s - Unix Epoch Time timestamp
%x - A date representation based on locale date, without the time

Miscellaneous :

%n - A newline character ("\n")
%t - A Tab character ("\t")
%% - A literal percentage character ("%")
optional string
timestamp An integer indicates the unixtimestamp. If a timestamp is not supplied, it gives the current local time. optional integer


Array return value

An array, or FALSE on failure.

The following list describes the elements of the returned array.
tm_sec - seconds.
tm_min - minutes.
tm_hour - hour.
tm_mday - day of the month.
tm_mon - month of the year, starting with 0 for January.
tm_year - Years since 1900.
tm_wday - Day of the week.
tm_yday - Day of the year.
unparsed - the date part which was not recognized using the specified format.

Example of php.js strptime() function:

In the following web document strptime() function parse time/date generated with strftime() function.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>php.js : strptime() function example</title>
<script type="text/javascript" src="../../phpjs/date/datetime.min.js"> </script>
<script type="text/javascript" src="../../phpjs/variable/variable.min.js"></script>
<h1 style="color: green">php.js : strptime() function example</h1>
<h3>Parse time/date generated with strftime() function </h3>
<hr />
<script type="text/javascript">
//This is done to make the following JavaScript code compatible to XHTML. <![CDATA[
format1 = "%d/%m/%Y %H:%M:%S";
strf1 = strftime(format1);
document.write(strf1+"<br />");
print_r(strptime(strf1, format1));

Output of the function:

07/07/2011 17:03:27
Array ( [tm_sec] => 27 [tm_min] => 3 [tm_hour] => 17 [tm_mday] => 7 [tm_mon] => 6 [tm_year] => 111 [tm_wday] => 4 [tm_yday] => 187 [unparsed] => )

Output vary time to time as current time changes.

View the example of php.js strptime() function in the browser

Download phpjs.zip

Previous: php.js : strftime() function
Next: php.js : strtotime() function

Follow us on Facebook and Twitter for latest update.