Article 6RGNS CodeSOD: Time to Change

CodeSOD: Time to Change

by
Remy Porter
from The Daily WTF on (#6RGNS)

Dennis found this little nugget in an application he inherited.

function myTime(){ $utc_str = gmdate("M d Y H:i:s", time()); $utc = strtotime($utc_str); return $utc;}

time() returns the current time as a Unix timestamp. gmdate then formats that, with the assumption that the time is in GMT. strtotime then parses that string back into a timestamp, and returns that timestamp.

Notably, PHP pins the Unix timestamp to UTC+00:00, aka GMT. So this function takes a time, formats it, parses the format to get what should be the same time back.

And we call the function myTime because of course we do. When reinventing a wheel, but square, please do let everyone know that it's yours.

proget-icon.png [Advertisement] Keep the plebs out of prod. Restrict NuGet feed privileges with ProGet. Learn more.
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments