Sponsored Content
Top Forums Shell Programming and Scripting JavaScript to get Timezone (IST, EST, etc) Post 302468497 by dahlia84 on Wednesday 3rd of November 2010 03:35:58 AM
Old 11-03-2010
JavaScript to get Timezone (IST, EST, etc)

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.

Code:
var d = new Date();
document.writeln(d)

This code gives

Code:
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

Code:
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

Code:
document.write(d.toTimeString());

this returns

Code:
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

Code:
 <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[i] == "(")
    {
        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[i]);
}

</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
Code:
Wed Nov 3 13:02:27 UTC+0530 2010

or

toTimeString

Sample Title
Code:
13:04:35 UTC+0530

So, there is no way I can manipulate the timezone string IST there Smilie
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Timezone

Hello again, under hp-ux i have a file /etc/TIMEZONE. here is definied which timezone i am. i dont know who reads this file to set after reading the timezone under /usr/lib/tztab. my 2 questions, who reads the file /etc/TIMEZONE ( which service ) and do i need in the first line to set my... (6 Replies)
Discussion started by: ortsvorsteher
6 Replies

2. UNIX for Dummies Questions & Answers

Timezone

Hi, I got an question about changing timezone thrue command line on a SunOS Release 4.1.2 without restarting the computer. Now it's set on WET and I want to set the timezone to CET (GMT +1) Plz somebody help me. Regards Novisern:confused: (5 Replies)
Discussion started by: Novisern
5 Replies

3. UNIX for Dummies Questions & Answers

timezone

Hi, i am searching to change the timezone on a HP-UX11 system. Since last weekend the summertime started i am not able to change the time to the new time, every day the time changes back to wintertime. I think the problem is that the server is on the wrong timezone. Can someone help me please?... (1 Reply)
Discussion started by: eddyvdv
1 Replies

4. UNIX for Advanced & Expert Users

Timezone

HI ; I got Solaris8 installed oon Sunfire V440 .I have TZ=GMT in /etc/TIMEZONE , but when i log in as root i see the date in GMT+1. So i have every time to "set TZ=GMT ; export $TZ" . How can i set the TZ=GMT at the startup defenitely. Thanks :) (7 Replies)
Discussion started by: oss
7 Replies

5. Shell Programming and Scripting

Changing the date to EST

Hi, The unix box has a system date in the PDT time zone format..if i need to capture the value of the date in a variable id do this: orderdate=`date '+%Y%m%d'` ordertime=`date '+%H%M%S'` output : $orderdate= 20060714 $ordertime= 043438 I need to convert and store this orderdate and... (2 Replies)
Discussion started by: shiroh_1982
2 Replies

6. Solaris

changing time zone from ist to bst

Hi, Can anybody tell me how to change time zone from ist to bst, What changes should be done in /etc/TIMEZONE file. wheather it is possible to change timezone without rebooting the server. Regards Manoj (1 Reply)
Discussion started by: manoj.solaris
1 Replies

7. UNIX for Advanced & Expert Users

Autosys run window in EST

Hi, I want to run a job in 5 min duration and start time should be 21:30EST and endtime should be 18:30EST nextday. in long note, it will start from sunday 21:30EST to monday 18:30EST......monday 21:30 EST to tuesday 18:30 EST....tuesday 21:30 ESTto wednesday 18:30EST...wednesday 21:30EST to... (1 Reply)
Discussion started by: millan
1 Replies

8. Shell Programming and Scripting

Displaying current date time of EDT in IST time

Hi Folks, My server time is in EDT. And i am sending automated mails from that server in which i need to display the current date time as per IST (GMT+5:30). Please advice how to display the date time as per IST. IST time leads 9:30 mins to EDT. and i wrote something like below. ... (6 Replies)
Discussion started by: Showdown
6 Replies

9. Linux

File size limitation in the EST 2012 x86_64 GNU/Linux

Hello Friends, I tried to take tar backup in my server, but it ended with an error. It said that: /home/back/pallava_backup/fbackup_backup/stape_config /home/back/romam_new.tar.gz tar: /home/backup/back.tar.gz: Cannot write: No space left on device tar: Error is not recoverable: exiting... (10 Replies)
Discussion started by: siva3492
10 Replies
All times are GMT -4. The time now is 10:30 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy