TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-10-2009, 01:39 AM   #1 (permalink)
The Acquainted
 
Randy's Avatar
 
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
Randy is on a distinguished road
Default Time Issues?

So im running a timestamp with my mysql and im using

PHP Code:
time() 
but im getting an output like this:

Quote:
1244597808
How would i go about making this a legit time like: 21:03

Thanks,
Randy
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
Send a message via AIM to Randy Send a message via MSN to Randy
Randy is offline  
Reply With Quote
Old 06-10-2009, 01:53 AM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

That is the Unix timestamp of the current time and date. It is the amount of seconds since midnight of January the 1st, 1970. It is pretty standard in the programming world because it takes everything into consideration, leap years included.

It contains all the data you require for the time and date, with a precision of a second.

If we're to convert that Unix timestamp you supplied then we would convert it using the date function, in the specified format. All the available formats are described on its PHP.net page.

Just from that data you supplied I can tell you that is 02:36:48 using the following line of code:

php Code:
echo date('H:i:s', 1244597808);

Unfortunately, I am not sure on the date because I've not requested that information, but the timestamp still contains that data.

To see the time and the date for that timestamp I can do the following to tell you what it is:

php Code:
echo date('d-m-Y H:i:s', 1244597808);

I now know that timestamp is the 10th of June, 2009 at 02:36:48. This is also timezone specific because to me there are still the same amount of seconds since 1970, as there are to you, because the changes in the timezone are relative.

At this very second the timestamp is 1244598646. In Google we can see that is the equivalent to a very precise 39.4397936 years.

Edit: Sorry, I probably misread your post as I am ever so tired. In MySQL you can do the following:

sql Code:
SELECT CURTIME();
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following 2 Users Say Thank You to Wildhoney For This Useful Post:
Randy (06-10-2009), Runar (06-10-2009)
Old 06-10-2009, 10:26 AM   #3 (permalink)
The Contributor
 
Runar's Avatar
 
Join Date: Nov 2008
Location: Norway
Posts: 58
Thanks: 20
Runar is on a distinguished road
Default

Great and simple explanation, Wildhoney! Even thou you answered the wrong question ;)


Yours, Runar
Send a message via MSN to Runar
Runar is offline  
Reply With Quote
Old 06-11-2009, 03:44 AM   #4 (permalink)
The Acquainted
 
Randy's Avatar
 
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
Randy is on a distinguished road
Default

He did answer it differently then i had expected but he gave me info on how to use that time format and just how put it correctly.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
Send a message via AIM to Randy Send a message via MSN to Randy
Randy is offline  
Reply With Quote
Old 06-11-2009, 03:46 AM   #5 (permalink)
The Acquainted
 
Randy's Avatar
 
Join Date: May 2007
Location: Your G/F's Closet
Posts: 114
Thanks: 7
Randy is on a distinguished road
Default

He did answer it differently then i had expected but he gave me info on how to use that time format and just output it correctly.
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25 - Andrew Rutherford
Send a message via AIM to Randy Send a message via MSN to Randy
Randy is offline  
Reply With Quote
Old 06-11-2009, 10:54 AM   #6 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Just a sidenote, you don't have to explicitly write the numbers there if you want the current time. You can just do this:

php Code:
echo date('d-m-Y H:i:s', time());
__________________
Tanax is offline  
Reply With Quote
Old 06-11-2009, 11:13 AM   #7 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
Just a sidenote, you don't have to explicitly write the numbers there if you want the current time. You can just do this:

php Code:
echo date('d-m-Y H:i:s', time());
If you're going to do that, just leave out the second argument entirely, date('d-m-y H:i:s');
Salathe is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Timezone Class: Dealing with Timezones the Proper Way Wildhoney General 2 01-10-2011 11:01 PM
Need more ideas for date and time class Wildhoney General 2 01-18-2008 02:22 PM
Two Different Ways to Format the Time CMellor Tips & Tricks 0 09-24-2007 11:12 PM
Script Execution Time Class Wildhoney Script Giveaway 2 09-14-2007 11:36 PM
Calculating the Execution Time Wildhoney Tips & Tricks 0 09-14-2007 11:14 PM


All times are GMT. The time now is 02:15 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design