·: Site description :·
Welcome!

NetBulge.com provides code, scripts, tips & tricks and general information about web development aimed to help webmasters and web designers.

Instead of packing all the info we can get into a huge database, our goal is to produce a high quality compilation of code snippets and articles. Web developers will find in these pages a fresh and savvy view of most of the issues concerning programming and designing for the web; as well as a good site to visit regularly for help and inspiration.

Enjoy!
Zones
Navigation
Search

Sessions

NetBulge.com RSS2 feed



About Hosting:

I use and recommend Hostgator for all my hosting needs. It is the only company I have tried (and I have tried plenty) that hasn't given me a headache and responds quickly and fairly to everything I ever need. I run 3 accounts that host over 20 sites with Hostgator and I am happy recommending it to all my family, friends and clients. If you are looking for a cheap yet solid host, IMO Hostgator is the way to go. I do get a comission if you register through the link, but even if you don't like me and don't want me to get a comission, go to Hostgator for your hosting needs and save yourself plenty of cash and headaches.


 Print version Send article via e-mail  

Fix server time and date in script


web zone resourcesVery often, the servers hosting our scripts are not in the same time zone as our target visitors. In order to use the current time and date, the server info must first be recalculated adding (or subtracting) the time difference.


Here is a simple script that illustrates how to achieve the change. You can easily add or subtract any amount of time, ranging from 1 second to multiple years:

<?php

//Today's date and time
echo "Today's date: " . date("j-n-Y") . "<br>";
echo "Current time: " . date("h:i:s") . "<br>";

//Add to the current date and time using mktime - store in a variable
$now= date("j-n-Y h:i:s", mktime(date("h"), date("i"), date("s"), date("n"), date("j"), date("Y")));

//By arithmetically adding to the separated values, mktime calculates the new date info
$altered= date("j-n-Y h:i:s", mktime(date("h")+1, date("i"), date("s"), date("n"), date("j")+1, date("Y")));

echo "<br>NOW, using mktime for timestamp: <br>" . $now . "<br>";
echo "<br>NOW + 1 day + 1 hour: <br>" . $altered . "<br>";

?>

In this example, I’m using the mktime function to recalculate the time / date and the date function to format the output. The code prints the current date and time, then stores in a variable the result of adding one hour and one day.

You can personalize this code to fit your needs and then save it to a file. Afterwards, it will be easy to include the file in your scripts and use the $altered variable every time you are required to output the current time / date.

 




Author : Esopo, Read 4855 times, Comments: 1
Rating :  rating resourcesrating resourcesrating resourcesrating resourcesrating resourcesrating resourcesrating resourcesrating resourcesrating resourcesrating resources  |  Thursday, 11. August 2005

Add new comment/Comments
Your rating :   Poor ranking resourcesrating resourcesrating resourcesrating resourcesrating resources Excellent




css stylescss stylesAre your scripts homeless?
NetBulge.com is devoted to web development. If you are too, then this is the site to house your best scripts and articles. Think about it: exposure, knowledge sharing and free rent. Join us!

Featured *
The Notepad on steroids. Quickness and simplicity, the Notepad’s two most acclaimed features are the core of this little editor; except Notepad2 goes the extra mile to provide syntax highlighting, brace matching, auto indent, rectangular selection, etc. With this tool around, there is no reason to have the original Notepad on your PC. (Source code available)

If you are a web developer, this link is a must in your quick-links bar. A visit to this site will clear even the most diligent creative-block.
http://www.k10k.net/