Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert a UTC Time to display quickly 1

Status
Not open for further replies.

cchipman

IS-IT--Management
Sep 16, 2002
125
US
I've got a UTC time from an LDAP query to active directory in the form of

"YYYYMMDDHHMMSS.0Z"

Is there a quick function similar to the "date" function that will convert it to a more printable format?

TIA.
 
The good news is that PHP provides the function strtotime() to convert date strings to timestamp integers. date() can then accept that integer as its optional second parameter.

The bad news is that strtotime() doesn't understand the format of "YYYYMMDDHHMMSS.0Z".

The good news is that through the judicious insertion of dashes, spaces and colons, the string can be converted into something strtotime() understands: "YYYY-MM-DD HH:MM:SS"

One way to add the dashes is through a regular expression. There are certainly others:

Code:
<?php
$string = '20050609042311.0Z';

$string1 = preg_replace ('/^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(.*)/', '$1-$2-$3 $4:$5:$6', $string);

print date ('Y-m-d', strtotime($string1));

?>


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Sweet. That was very helpful. I really appreciate the assistance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top