473,739 Members | 7,912 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting timezoneoffset using js in php

I have a php page which uses checks to see if the tz variable is in the
argument list.. if not, it recalls the page using javascript with the added
tz argument.. if I run it locally here in the UK, the tz is set to 0 which
is correct. If I run it on a US server, it initially returns -1, but in IE
if I do a ctrl-refresh, it correctly gets it as 0.

Any ideas ?

<?php
if (!isset($_GET['tz'])) print "
<script type=\"text/javascript\">
now = new Date();
window.location .href=\"$_SERVE R[PHP_SELF]?tz=\" + (now.getTimezon eOffset() /
60);
</script>";

Jul 23 '05 #1
2 2442
Adrian Parker wrote:
I have a php page which uses checks to see if the tz variable is in the
argument list.. if not, it recalls the page using javascript with the added
tz argument.. if I run it locally here in the UK, the tz is set to 0 which
is correct. If I run it on a US server, it initially returns -1, but in IE
if I do a ctrl-refresh, it correctly gets it as 0.

Any ideas ?

<?php
if (!isset($_GET['tz'])) print "
<script type=\"text/javascript\">
now = new Date();
window.location .href=\"$_SERVE R[PHP_SELF]?tz=\" + (now.getTimezon eOffset() /
60);
</script>";


--test.php--

<?php
if (!isset($_GET['tz'])) print "
<script type=\"text/javascript\">
now = new Date();
window.location .href=\"$_SERVE R[PHP_SELF]?tz=\" + (now.getTimezon eOffset() /
60);
</script>";

print $_GET['tz'];
?>

Loaded from Apache/1.3.31 (Unix) mod_ssl/2.8.17 OpenSSL/0.9.7d PHP/4.3.9

Loaded into IE 6.0.2800 (pre Windows XP Service Pack 2) and IE 6.0.2900 (Windows
XP Service Pack 2), as well as Mozilla Firefox 0.10.1 (1.0PR) all display "6"
(I'm currently in CDT - Central Daylight Savings Time). So it appears to be
working correctly. You can streamline the JavaScript a bit by making it:

<script type=\"text/javascript\">
window.location .href=\"$_SERVE R[PHP_SELF]?tz=\" + ((new
Date()).getTime zoneOffset() / 60);
</script>

But that shouldn't affect the result.

--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq

Jul 23 '05 #2
JRS: In article <41************ ***@agricoreuni ted.com>, dated Tue, 2
Nov 2004 21:41:09, seen in news:comp.lang. javascript, Grant Wagner
<gw*****@agrico reunited.com> posted :

Loaded into IE 6.0.2800 (pre Windows XP Service Pack 2) and IE 6.0.2900 (Windows
XP Service Pack 2), as well as Mozilla Firefox 0.10.1 (1.0PR) all display "6"
(I'm currently in CDT - Central Daylight Savings Time). So it appears to be
working correctly. You can streamline the JavaScript a bit by making it:

<script type=\"text/javascript\">
window.locatio n.href=\"$_SERV ER[PHP_SELF]?tz=\" + ((new
Date()).getTim ezoneOffset() / 60);
</script>

But that shouldn't affect the result.


I see possible difficulties if the code is executed with settings for
Newfoundland, India, etc., where getTimezoneOffs et()/60 is not integer.
And, indeed, where it is negative.

--
© John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
Web <URL:http://www.merlyn.demo n.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demo n.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6928
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on a type mismatch. It is positively because of the boolean(java primitive)parameter. It goes fine if I change this parameter to int or String. This inteface has a lot more methods which works fine, it is just the
8
10014
by: Rod | last post by:
I have been working with ASP.NET 1.1 for quite a while now. For some reason, opening some ASP.NET applications we wrote is producing the following error message: "The Web server reported the following error when attempting to create or open the Web project located at the following URL: 'http://localhost/WebApplication1'. 'HTTP/1.1 500 Internal Server Error'."
3
3088
by: Hitesh | last post by:
Hi, I am getting the response from another Website by using the HttpHandler in my current site. I am getting the page but all the images on that page are not appearing only placeholder are displayed. Can anybody know this issue and help me to resolve this. In past i received the response saying that i should download the image first and then parse the actual response and modify the src attribute of the
4
4507
by: R.Manikandan | last post by:
Hi In my code, one string variable is subjected to contain more amount of characters. If it cross certain limit, the string content in the varabile is automatically getting truncated and i am not getting the full data. Is there any max limit for an variable to store in javascript? Can anyone please help me to solve this prob?
3
2134
by: manicmax | last post by:
when i am calling a perl script on action of the form.like this <form action="https://someurl/cgi-bin/abc-login.pl?servletLoc=/servlets/iclientservlet/sadf/&cmd=login&languageCd=ENG" method="post" id="login" name="login" autocomplete=off onSubmit="signin(document.login)"> the signin function is given below: function signin(form) { var now=new Date(); form.timezoneOffset.value=now.getTimezoneOffset(); return ;
5
9120
by: Archana | last post by:
Hi all, I am having application where i am downloading xml content using webrequest. my code is as below HttpWebRequest lWebRequest = (HttpWebRequest) WebRequest.Create(URL); HttpWebResponse lWebResponse = (HttpWebResponse) lWebRequest.GetResponse(); StreamReader lResponseStream = new StreamReader(lWebResponse.GetResponseStream(),enc); Data = lResponseStream.ReadToEnd();
2
3080
by: Manikandan | last post by:
Hi, I have a program written in .Net Framework 1.1 using Visual studio enterprise edition 2003. I tried compiling the same program in visual c# express edition 2005. I'm getting following errors 1.Error 6 Cannot implicitly convert type 'mscomctl.Toolbar ' to 'mscomctl.Toolbar . An explicit conversion exists (are you missing a
3
9558
by: tshad | last post by:
I have a file that I converted from VB.Net to C# that works fine in VB.Net when I compile but not in C# using the same libraries. The error I am getting is: PageInit.cs(9,7): error CS0138: A using namespace directive can only be applied to namespaces; 'System.Web.HttpCookie' is a class not a namespace The code is:
4
5725
by: imaloner | last post by:
I am posting two threads because I have two different problems, but both have the same background information. Common Background Information: I am trying to rebuild code for a working, commercially sold application with only partial build instructions. The previous maintainer of the code (a mixture of C and C++) is no longer with the company, but when he built the code he used MSVC++, and though I am not certain of the version he was ...
0
8969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9479
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9337
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6754
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4826
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.