Unix timestamps are a way or storing a specific date and time. Unix timestamps are a 10 digit number that represents the number of seconds that have passed since midnight Universal Co-ordinated Time (UTC) of January 1st, 1970.
What makes timestamps ever so useful is that since timestamps are recorded as of UTC (or GMT) a single time stamp can be used to to represent all time zones. Once you have your timezone, the unixtime stamp will adjust the time accordingly. For example, a unix timestamp of 1304951846 can represent 10th May at 0:37 AM in London, but it would also represent 10th May at 10:37 AM in Brisbane/Australia.
Why Unix Timestamp Is Useful
How can this be useful? Just think, users can see dates and times on your website relative to their own timezone, rather than the timezone of the server the website is being run on. Being a web developer, I am forever finding myself storing dates do be displayed back to the user. It may be a date a user last logged into a program or website, perhaps even a date that a user posted an article such as this to a website. Once we store a specific timestamp, we can display the time and date to users but also in the correct relevant timezone. On top of which, timestamps are easy to use, and many languages support them.
Online Timestamp Converter
PHP can convert a timestamp to a human readable format by using the date() function and likewise using strtotime() and mktime() to convert a natural language string to a unixtime stamp to be stored. Short examples are:
PHP Timestamp Example
<?php /* convert unixtime stamp to human time */ echo date('d F Y H:i:a',1304951846); // would display a time of 10 May 2011 00:37:am /* convert to a unix time stamp */ echo strtotime('+1 Year'); // would return the timestamp of 1 year from today echo mktime($hour,$min,$sec,$month,$day,$year); // echo a timestamp specified by the variables ?>
MySQL Timestamp Example
MySQL uses the syntax FROM_UNIXTIME to convert data to a human readable format for example:
SELECT *,FROM_UNIXTIME(timestamp_column) FROM `table`;