If I have done it correctly, it should show the current time in Victoria, while taking daylight savings into consideration.
Have I done the nested if conditions correctly?
Code:
if
{
if
{
blah1
}
else
{
blah2
}
}
And is that a good way of doing nested if's? (Or even an acceptable way?
Code below in its entirety.
Code:
<html>
<head>
<script type="text/javascript">
function startVic() {
var nowvica = new Date();
var yrvica = nowvica.getYear();
var DSTusedvica = false;
var janvica = new Date(yrvica,0,1); // 1st January in current year
var janoffvica = janvica.getTimezoneOffset();
var julvica = new Date(yrvica,6,1); // 1st July in current year
var juloffvica = julvica.getTimezoneOffset();
// alert ("January " + janoff + " July " + juloff); // for testing
if (janoffvica != juloffvica) {
DSTusedvica = true;
}
if (DSTusedvica) {
var ntzovica = nowvica.getTimezoneOffset();
if (ntzovica == juloffvica) {
// DST is in operation
}
else {
// DST is not in operation
}
}
var nowvic = new Date();
var hvic=nowvic.getUTCHours();
var minvic=nowvic.getUTCMinutes();
var svic=nowvic.getUTCSeconds();
if (hvic>12) {hvic-=12}
if (hvic==0) {hvic=12};
if (ntzovica == juloffvica)
{
if (hvic<=2)
{
hvic=hvic+10
}
else
{
hvic=hvic-2
}
}
else
{
if (hvic<=1)
{
hvic=hvic+11
}
else
{
hvic=hvic-1
}
}
if (minvic<10) {minvic="0"+minvic}
if (svic<10) {svic="0"+svic}
document.getElementById("timevic").innerHTML=hvic+":"+minvic+":"+svic;
var timvic = setTimeout("startVic()",1000);
}
</script>
</head>
<body onload="startVic()">
<span id="timevic"></span>
</body>
</html>
Is there any way I can add "setTimezone("AEST");" or setTimezone("Australia/Melbourne");" into the coding somewhere or something similar to the DST check (see above) so it checks if it is daylight savings or not in Victoria, regardless of the timezone it is running from?
Is there any way I can add "setTimezone("AEST");" or setTimezone("Australia/Melbourne");" into the coding somewhere or something similar to the DST check (see above) so it checks if it is daylight savings or not in Victoria, regardless of the timezone it is running from?
No. As I said before, it is possible to detect whether DST is used and is currently in operation in the user's own country, but AFAIK it is not possible for a user in one country to detect whether DST is currently in operation in some other country, e.g. Japan or Argentina.
In any case, why does it matter to a user in (say) New Zealand whether or not DST is currently in operation in Victoria Australia?
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Unless I am mistaken, because we are telling the clock to go to UTC time then add 10 hours, during daylight savings time (+11 hours instead of +10) the clock would be 1 hour off. It's not hugely important for this implementation as it may only get used in Victoria, but something I'll try to look into as the next upgrade so it can actually get used cross-state (and then post the code here for an open/closed taking DST into consideration script)
I'll post the entire working code in the next day or so - as best as I can tell it is all working, I just want to bug hunt and double-check myself.
Do the states of Australia have different dates of implementation of DST?
I now see that those states that do use DST use the same dates, but not all Australian states use DST.
And there are three different time zones in Australia.
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Do the states of Australia have different dates of implementation of DST?
I now see that those states that do use DST use the same dates, but not all Australian states use DST.
And there are three different time zones in Australia.
Yeah, if they all used DST at the same time it would not be an issue at all!
There's been a few times where the use of DST has been questioned by us Aussies, but nothing has happened of it. Go figure!
I was busy looking for a way of working out how to find out the DST in a specific timezone clientside - I found a few ways server-side using Ruby on Rails or PHP but nothing in Javascript.
I'll keep looking and see what I can find, then update this thread.
I was busy looking for a way of working out how to find out the DST in a specific timezone clientside - I found a few ways server-side using Ruby on Rails or PHP but nothing in Javascript.
As I have already tried to explain, it is not possible using client-side code.
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.