Software, your way.
burger menu icon
WillMaster

WillMaster > LibraryGenerators and Converters

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Extracting Dates From the Unix Timestamp

In my work, I frequently deal with the Unix timestamp. It is a number that represents how many seconds have elapsed since midnight, January 1, 1970 UTC. It was established with the Unix operating system when the developers wanted a simple and consistent way to represent time.

The timestamp is frequently found in database and log files.

Currently, the timestamp is a 10-digit number. The last 9-digit timestamp occurred September 9, 2001 at 1:46:39 UTC. The 11-digit timestamp won't happen until November of the year 2286.

Here is an example.

1734438615

The beauties of the Unix timestamp are that (i) it requires very little room when stored in files and (ii) it can be used to determine the represented time for any time zone on Earth.

Of course, I made a tool to extract the date and time from the timestamp. You'll find it at the Date and Time tools page.

It is fairly simple code if you wish to do it yourself, instead of using the tool linked to above. This line of PHP code will do the trick.

echo date('r',1234567890);
/* Assuming 1234567890 is the timestamp. */

The 'r' format specification results in a human-readable datetime. (Technically, it is an RFC 5322 formatted date.) The date is formatted in this way:

Fri, 13 Feb 2009 23:31:30 +0000

Other formats can be specified. I like 'r' because it is succinct and the format parameter is easy to remember. See the DateTime Formats page for a list of characters that can be used when specifying your preferred format.

Notice that the formatted datetime example, above, ends with +0000. That means the datetime was calculated for UTC. The number indicates the plus or minus offset for the time zone the datetime was calculated for. A number other than +0000 would indicate a different time zone.

As stated further above, the code in this article is provided so you can make your own if you wish to do so.

Whether or not you make your own, you are welcome to use the Date and Time tools page to extract the datetimes from Unix timestamps. (The tools page also has a reverse converter, date/time to timestamp.)

(This content first appeared in Possibilities newsletter.)

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC