Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Add BST & GMT to this javascript?

Original Message
Name: Stephen Allden
Date: October 7, 2006 at 18:09:56 Pacific
Subject: Add BST & GMT to this javascript?
OS: Microsoft Windows XP Prof
CPU/Ram: 534 MHz/192 MB
Model/Manufacturer: Packard Bell (Nec)
Comment:
Hiya,

I have a page on my website with a JavaScript code on which basically displays different images at different times of the day but the problem is the code looks for the visitors system time and I don't want it to do that, does anyone know how I add a BST (British summer time) and GMT function to the following code...

http://www.stephenallden.co.uk/javascript_code.htm

Cheers!!!


Report Offensive Message For Removal


Response Number 1
Name: Michael J (by mjdamato)
Date: October 7, 2006 at 22:06:06 Pacific
Subject: Add BST & GMT to this javascript?
Reply: (edit)
Add the items in blue to make the visitor's time GMT time. (make any adjustment you need to make it BST):

day=new Date();
offset = time.getTimezoneOffset();
h = day.getHours()*60;
m = day.getMinutes();
time = h + m + offset;

Michael J


Report Offensive Follow Up For Removal

Response Number 2
Name: Michael J (by mjdamato)
Date: October 7, 2006 at 22:28:28 Pacific
Subject: Add BST & GMT to this javascript?
Reply: (edit)
I just realized, because you will be adjusting the user's time it will be possible to get invalid times (i.e. less than 0 or greater than 1440). So, you will need to adjust for this. Also, your last "if" statement is not needed. If none of the other conditions were met, you just need the else statement.

I also made some changes to make the code a little more compact. Here is the entire code with the modifications needed:

==========BEGIN CODE==============

day = new Date();
hours = day.getHours()*60;
minutes = day.getMinutes();
offset = day.getTimezoneOffset();
time = hours + minutes + offset;

if (time < 0) {time = time + 1440}
if (time > 1440) {time = time - 1440}

if (time<300) {img = '1';} // 12:00 am
else if (time<600) {img = '2';} // 5:00 am
else if (time<720) {img = '3';} // 10:00 am
else if (time<840) {img = '4';} // 12:00 pm
else if (time<960) {img = '5';} // 2:00 pm
else if (time<1020) {img = '6';} // 4:00 pm
else if (time<1050) {img = '7';} // 5:00 pm
else if (time<1140) {img = '8';} // 5:30 pm
else if (time<1320) {img = '9';} // 7:00 pm
else {img = '10';} // 10:00 pm

document.write('[img border="1" src="'+img+'.gif" width="64" height="64"]');

==========END CODE==============

Note: replace the [] in the last line with <>. Changed for posting purposes.


Michael J


Report Offensive Follow Up For Removal

Response Number 3
Name: Stephen Allden
Date: October 8, 2006 at 10:34:42 Pacific
Subject: Add BST & GMT to this javascript?
Reply: (edit)
Hiya what part of the code do i add the BST, do i remove the getTimezoneOffset from the line offset = day.getTimezoneOffset();

Cheers!!!


Report Offensive Follow Up For Removal

Response Number 4
Name: Michael J (by mjdamato)
Date: October 8, 2006 at 18:14:49 Pacific
Subject: Add BST & GMT to this javascript?
Reply: (edit)
"Hiya what part of the code do i add the BST, do i remove the getTimezoneOffset from the line offset = day.getTimezoneOffset();"

No, the getTimezoneOffset function gets the offset from the user's time (based upon their computer settings) from GMT. So the line time = hours + minutes + offset; sets the variable "time" to the current GMT based upon the time set for the user's computer. You would need to adjust that to get BST.

For example, if BST is 2 hours ahead of GMT then you would change the line accordingly:

time = hours + minutes + offset + 120;

A couple things to remember. This is dependant on the fact that the user's timezone is set correctly on their computer and that their time is correct. Also, there is no way to account for daylight savings time is the user is using that.

To really do this correctly it would be better to use some server side scripting.

Michael J


Report Offensive Follow Up For Removal

Response Number 5
Name: Stephen Allden
Date: October 11, 2006 at 18:09:42 Pacific
Subject: Add BST & GMT to this javascript?
Reply: (edit)
Hiya Michael J,

Thanks for the above code mate work brilliant just what i needed cheers. How do i change the code so that instead of images i can have text displaying with the capability of changing font name, size, colour, etc.

Cheers!!!


Report Offensive Follow Up For Removal


Response Number 6
Name: Michael J (by mjdamato)
Date: October 11, 2006 at 22:26:27 Pacific
Subject: Add BST & GMT to this javascript?
Reply: (edit)
Change the variable text of the if conditions to what you want each of the different displays to be. Then change the code within the document.write function to be whatever format you want the variables to be displayed.

document.write('[span style="font-size:12pt;font-weight:bold;"]VariableText[/span]');

Michael J


Report Offensive Follow Up For Removal

Response Number 7
Name: Stephen Allden
Date: October 12, 2006 at 06:54:15 Pacific
Subject: Add BST & GMT to this javascript?
Reply: (edit)
Hiya Michael J,

I've made the necessary changes as you suggested but it don't seem to work, can you have a look at the code below and tell me what I’ve done wrong,

Cheers!!!

------------------- CODE --------------------

day = new Date();
hours = day.getHours()*60;
minutes = day.getMinutes();
offset = day.getTimezoneOffset();
time = hours + minutes + offset + 60;

if (time < 0) {time = time + 1440}
if (time > 1440) {time = time - 1440}

if (time<300) {span = '12:00AM - 5:00AM';} // 12:00 am
else if (time<600) {span = '5:00AM - 10:00AM';} // 5:00 am
else if (time<720) {span = '10:00AM - 12:00PM';} // 10:00 am
else if (time<840) {span = '12:00PM - 2:00PM';} // 12:00 pm
else if (time<1140) {span = '2:00PM - 7:00PM';} // 2:00 pm
else if (time<1230) {span = '7:00PM - 8:30PM';} // 7:00 pm
else if (time<1320) {span = '8:30PM - 10:00PM';} // 8:30 pm
else {span = '10:00PM - 12:00AM';} // 10:00 pm

document.write('<span style="font-size:12pt;font-weight:bold;"]VariableText</span>');

----------------


Report Offensive Follow Up For Removal

Response Number 8
Name: Michael J (by mjdamato)
Date: October 12, 2006 at 07:15:44 Pacific
Subject: Add BST & GMT to this javascript?
Reply: (edit)
Sure, but please when posting a problem, try to be descriptive. Just saying "it don't seem to work" tells me nothing about what the problem might be.

It looks like you just tried to do it in a rush. I'm sure if you were to look over your code you would see the problem. In the IF statements you are creating a variable called "span". But in the document.write command there are two problems.

1) You are not using the "span" variable you created before.

2) You left one of the square brackets in. It needs to be changed to a ">".

This should work:
document.write('<span style="font-size:12pt;font-weight:bold;">'+span+'</span>');

Michael J


Report Offensive Follow Up For Removal

Response Number 9
Name: Stephen Allden
Date: October 12, 2006 at 07:52:15 Pacific
Subject: Add BST & GMT to this javascript?
Reply: (edit)
Sorry about that Michael J!!!

How bout making the code to open another page (new.htm) in a new window (tarfet="_blank")

Cheers!!!

Really appreciate your help, i'm useless at this stuff :-)!!!


Report Offensive Follow Up For Removal

Response Number 10
Name: Michael J (by mjdamato)
Date: October 12, 2006 at 20:37:15 Pacific
Subject: Add BST & GMT to this javascript?
Reply: (edit)
Open WHAT in a new page?

Just change the document.write command to "print" whatever youwant to the page. Just take a look at how the content is formatted and you can make it whatever you want.

In the below example anything inside the parens () is printed. You need to encolse "text" within single quotes and you append pieces of text and variables with the add symbol (+). I have color coded the text as follows.

Javascript function - black
Text - red
Variables - blue

document.write('<span style="font-size:12pt;font-weight:bold;">'+span+'</span>');

I believe that if you give a man a fish he will eat for a day. Teach him to fish and you feed him for life. So, with that I leave you to at least ATTEMPT to make the changes yourself. If you have trouble post back with the code you have and the problems you are experiencing. Good luck.


Michael J


Report Offensive Follow Up For Removal

Response Number 11
Name: Stephen Allden
Date: October 13, 2006 at 13:54:37 Pacific
Subject: Add BST & GMT to this javascript?
Reply: (edit)
Hiya Michael, no luck mate, had a crack at it but it didn't work, i'll get there one day!!!

------------------- CODE --------------------

day = new Date();
hours = day.getHours()*60;
minutes = day.getMinutes();
offset = day.getTimezoneOffset();
time = hours + minutes + offset + 60;

if (time < 0) {time = time + 1440}
if (time > 1440) {time = time - 1440}

if (time<300) {a href= '1';} // 12:00 am
else if (time<600) {a href= '2';} // 5:00 am
else if (time<720) {a href= '3';} // 10:00 am
else if (time<840) {a href= '4';} // 12:00 pm
else if (time<1140) {a href= '5';} // 2:00 pm
else if (time<1230) {a href= '6';} // 7:00 pm
else if (time<1320) {a href= '7';} // 8:30 pm
else {a href= '8';} // 10:00 pm

document.write('');

----------------

Thanks for everything, really appreciate your help!


Report Offensive Follow Up For Removal

Response Number 12
Name: Stephen Allden
Date: October 13, 2006 at 13:56:09 Pacific
Subject: Add BST & GMT to this javascript?
Reply: (edit)
Ooops!!! forgot the document.write bit, sorry!!!

document.write('[a href target="_frame758500" src="'+a href+'.htm"]');


Report Offensive Follow Up For Removal

Response Number 13
Name: Michael J (by mjdamato)
Date: October 13, 2006 at 23:15:00 Pacific
Subject: Add BST & GMT to this javascript?
Reply: (edit)
Variables can't have a space in them. Change "a href' to "ahref" or just "href".

When in doubt keep it simple.

Michael J


Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Add BST & GMT to this javascript?

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




Batch File- Current Date in Excel

how to setup call of duty to joytok

WindowsME / HotMail Problem

Corrupt memory

Convert fat32 to Ntfs


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC