Friends,
I am trying to write a Javascript to get the local timezone (not UTC+5.30, etc but exactly like IST, PST, etc). I been trying for two days and I am finally here to ask for some pointers. I did googling and found the getTimezoneOffset function as well but I can not make use of it to get the desired result.
var d = new Date();
document.writeln(d)
This code gives
Wed Nov 3 10:34:18 UTC+0530 2010
Here, the UTC+0530 is the timezone which I have set in my system. but how will I make this UTC+0530 to become IST ?
I can go ahead and make a if condition for it but what if someone else in the US/any other country is trying to use this script? their case will be left out. So, it is practically impossible to put a lot of such IF conditions to check and print the Timezone as such.
I even checked out this site
hunlock.com/blogs/Javascript_Dates-The_Complete_Reference
I have tried all the functions which they have shown their but none of them seem to help me with what I want.
So, is there any way anyone aware of to print the timezone in ISt, GMT, EST, PST formats?
---------- Post updated at 11:42 AM ---------- Previous update was at 10:42 AM ----------
Guess I have found a way.. might not be the best
document.write(d.toTimeString());
this returns
11:41:26 GMT+0530 (India Standard Time)
So, i think I may have to cut the Initial Alphabets of that string that's inside the bracket.
---------- Post updated at 12:21 PM ---------- Previous update was at 11:42 AM ----------
In case anyone else is interested, here is the script that gives you the timezone abbrviation alone
<script type="text/javascript">
var d = new Date();
sd=d.toTimeString();
var a1 = new Array();
a1=sd;
var tz = new Array();
var k=0;
for (i=0;i<a1.length;i++)
{
if (a1 == "(")
{
tz[k]=a1[i+1];
for (j=i+1;j<a1.length;j++)
{
if (a1[j] == " ")
{
tz[k+1]=a1[j+1];
k=k+1;
}
}
}
}
for (i=0;i<3;i++)
{
document.write(tz);
}
</script>
---------- Post updated at 01:05 PM ---------- Previous update was at 12:21 PM ----------
Oh damn! This works only in firefox.
The stupid IE, outputs only
toString
Sample Title
Wed Nov 3 13:02:27 UTC+0530 2010
or
toTimeString
Sample Title
13:04:35 UTC+0530
So, there is no way I can manipulate the timezone string IST there