This function is used when your have Overseas server, let's say your server is on GMT-7 and your Local time is on GMT +7, then you want your script time to use your Local (GMT+7) time.
By : hermawan
<?php
/***********************************************
* Snippet Name : convgmt *
* Scripted By : Hermawan Haryanto *
* Website : http://hermawan.com *
* Email : hermawan@codewalkers.com *
* License : GPL (General Public License) *
***********************************************/
function convgmt ($cgmt) {
$now = time();
$sgmt = date("Z");
$sgmt = $sgmt/3600;
$diffh = $sgmt.$cgmt;
if (is_int(strpos("-",$cgmt))) {
$diffh = eval($diffh);
} else {
$diffh = $sgmt - $cgmt;
}
$realtime = $now - ($diffh*3600);
return $realtime;
}
Header ('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
Header ('Last-Modified: '. gmdate("D, d M Y H:i:s") .' GMT');
Header ('Cache-Control: no-store, no-cache, must-revalidate');
Header ('Cache-Control: post-check=0, pre-check=0', false);
Header ('Pragma: no-cache');
$gmt = $_GET["gmt"];
if (!isset($gmt)) $gmt = 7;
print date("G:i:s l, F jS Y", convgmt($gmt));
print "<br>";
print date("g:i:s a l, F jS Y", convgmt($gmt));
for ($i=-12;$i<=13;$i++) {
if($i<0) {
$j = substr($i,1,strlen($i));
if (strlen($j)==1) $j = "0".$j;
$j = "GMT-$j:00";
$x = $i;
} else {
if (strlen($i)==1) {
$j = "0".$i;
} else {
$j = $i;
}
$j = "GMT+$j:00";
$x = "+".$i;
}
if (!isset($gmt)) {
if ($i == 7) {
$rtn .= "<option value='$x' selected>$j</option>";
} else {
$rtn .= "<option value='$x'>$j</option>";
}
} else {
if ($i == $gmt) {
$rtn .= "<option value='$x' selected>$j</option>";
} else {
$rtn .= "<option value='$x'>$j</option>";
}
}
}
?>
<form method="get">
<select name="gmt"><?=$rtn;?></select> <input type="submit" value="Get My Time">
</form>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Date Time Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
As businesses grow increasingly dependent upon Web applications to provide services to customers, employees and partners, these complex applications become more difficult to secure. Although traditional security solutions protect Internet infrastructure layers, they do not guard against HTTP and HTML attacks. Many organizations that conduct security testing still deploy applications that allow attackers to manipulate their logic and wreak havoc on their business. To mitigate this risk, development and delivery teams must address Web application security throughout the lifecycle, addressing the many layers detailed in this paper. FREE! Go There Now!
|
|
|
|
Effective governance for lean development isn’t about command and control. Instead, the focus is on enabling the right behaviors and practices through collaborative and supportive techniques. Hear from Scott Ambler on how it is far more effective to motivate people to do the right thing than it is to force them to do so. Learn how to form a lightweight, collaboration-based framework that reflects the realities of modern IT organizations. FREE! Go There Now!
|
|
|
|
Download the Rational Application Developer (RAD) v7.5 open beta code and start developing applications for the JEE5 standard which features EJB3.0, JPA, JSF 1.2, JSP 2.1 and Servlet 2.5 standards. When you use this beta you will see how you can increase developer productivity for already existing applications with improved support for refactoring, as well as adding new features to existing applications. In addition, the beta provides tooling for JD Edwards, Oracle, SAP, Siebel and PeopleSoft to improve the developer productivity with these enterprise systems. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of WebSphere Extended Deployment Compute Grid, which lets you schedule, execute, and monitor batch jobs. Because online transaction processing and batch jobs execute simultaneously on the same server resources, you can avoid costly duplication of resources. Compute Grid supports job types of Java transactional batch, compute-intensive and a new type called "native execution", which enables non-Java workloads to run on distributed end points. FREE! Go There Now!
|
|
|
|
Join us for this web seminar to learn how you can defend your web applications from attack. Learn about the 3 most common web application attacks, including how they occur and what can be done to prevent them. We’ll also discuss manual versus automated approaches for scanning and identifying web application vulnerabilities and how IBM Rational AppScan, an automated vulnerability scanner, can help you automate more of what you are doing manually today. FREE! Go There Now!
|
|
|
|
Manage, govern, and share services across your organization by using WebSphere Service Registry and Repository. Follow the hands-on exercises to learn how to navigate the Web interface to publish, find, reuse, and update services. FREE! Go There Now!
|
|
|
|
Secure your Web applications with IBM Rational AppScan Standard Edition V7.7, previously known as Watchfire AppScan. This Web application security testing tool automates vulnerability assessments and scans and tests for common Web application vulnerabilities. Visit IBM developerWorks to download a free trial of IBM Rational AppScan Standard Edition V7.7. FREE! Go There Now!
|
|
|
|
Rational Build Forge Express Edition is an automation framework that packages the latest enterprise-grade technologies into a reliable, flexible and robust configuration designed and priced specifically for small to midsize businesses. The new Rational Build Forge Express eKit provides you with valuable resources – including a case study, podcast, demo, and articles – to help you increase staff productivity, compress development cycles and deliver better software, fast. FREE! Go There Now!
|
|
|
|
Get a free trial download of the latest version of IBM Rational Performance Tester V7.0.1, a load and performance testing solution for teams concerned about the scalability of their Web-based applications. Combining multiple ease-of-use features with granular detail, Rational Performance Tester simplifies the test-creation, load-generation and data-collection processes that help teams ensure the ability of their applications to accommodate required user loads. FREE! Go There Now!
|
|
|
|
Attend this launch webcast with Scott Hebner, Vice President of IBM Rational Marketing and Strategy, where he will overview Rational’s new offerings and programs to help customers accelerate software innovation on System z. He will discuss how these solutions help organizations extend their core business processes toward modern architectures such as SOA and web technologies to deliver business improvements that stand the test of time. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |