date

time

10 Dec 2007

In PHP, both mktime and gmtime yield the same unix_timestamp with no argument passed.

<?php

echo mktime() == gmmktime() ? 'eq' : ' not eq';

?>

yields 'eq'

However, mktime argument is "local time" but the gmmktime’s is "GMT time".

<?php

echo Date("D M Y H:i:s e", mktime(0,0,7,10,12,2007) );
echo '<br/>';
echo Date("D M Y H:i:s e", gmmktime(0,0,7,10,12,2007) );
?>

yields

Fri Oct 2007 00:00:07 Asia/Krasnoyarsk
Fri Oct 2007 08:00:07 Asia/Krasnoyarsk

Let’s compare this to .NET.

In .NET, class DateTime has responsibility to these kind of task. In fact, DateTime class has one static property to get current, local time (or day), DateTime.Now, and another property, DateTime.UtcNow, provides current universal time.  To calculate time, Timespan struct comes into play but I usually use various method on DateTime object to do so. Moreover, universal time is advised to use in time calculation.

DateTime d = DateTime.Now // get current local time
DateTime u = d.ToUniversalTime() // get universal time of corresponding time
DateTime l = u.AddHours(7); // plus 7 to hour, get time for Bangkok timezone.

Personally, .NET seems to be easier than PHP. Formatting date and time syntax is much better and more understandable than PHP.

Technorati tags: , , ,