JavaScript - Help: Converting Gmt Dates To Local Users Timezomes
Hi Javascript Gurus,
I've made a webpage which displays a list of timeslots in GMT time, and also conveniently displays the GMT times in the clients local time, depending on the timezone they have on their comp. The output on my computer (Melbourne +10 GMT) is perfect. It even anticipates a future Daylight Savings change. It looks like this: Code: Option 1: Saturday 24th Oct 20:00 GMT = YOUR time: Sunday, October 25, 2009 7:00:00 AM Option 2: Saturday 24th Oct 22:00 GMT = YOUR time: Sunday, October 25, 2009 9:00:00 AM Option 3: Saturday 24th Oct 24:00GMT = YOUR time: Sunday, October 25, 2009 11:00:00 AM Option 4: Sunday 25th Oct 20:00GMT = YOUR time: Monday, October 26, 2009 7:00:00 AM Option 5: Sunday 25th Oct 22:00 GMT = YOUR time: Monday, October 26, 2009 9:00:00 AM Option 6: Sunday 25th Oct 24:00 GMT = YOUR time: Monday, October 26, 2009 11:00:00 AM BUT when I switch my computer to a North American, or European time (to test) the Saturday times are one hour later than the Sunday ones!?! Here's an example (Central US time -6 GMT): Code: Option 1: Saturday 24th Oct 20:00 GMT = YOUR time: Saturday, October 24, 2009 3:00:00 PM Option 2: Saturday 24th Oct 22:00 GMT = YOUR time: Saturday, October 24, 2009 5:00:00 PM Option 3: Saturday 24th Oct 24:00GMT = YOUR time: Saturday, October 24, 2009 7:00:00 PM Option 4: Sunday 25th Oct 20:00GMT = YOUR time: Sunday, October 25, 2009 2:00:00 PM Option 5: Sunday 25th Oct 22:00 GMT = YOUR time: Sunday, October 25, 2009 4:00:00 PM Option 6: Sunday 25th Oct 24:00 GMT = YOUR time: Sunday, October 25, 2009 6:00:00 PM Daylight Savings happens in the US in November, so what's going on? thanks, Andrew K Similar TutorialsI am trying to launch an HTML page with a calendar field populated with today's date. I have a function to set the date but I am getting an error when I try to run the page: Code: //Begin function window_onload function window_onload() { UpdateData(); // TODO: Add your event handler code here function onInitialUpdate() { document.getElementById('calendar1').value=getTodaysDate(); } } //End function window_onload function getTodaysDate(){ var today = new Date(); var dd = today.getDate(); var mm = today.getMonth()+1; var yyyy = today.getFullYear(); if(dd<10){dd='0'+dd} if(mm<10){mm='0'+mm} var today = yyyy+'/'mm+'/'+dd; alert('Today is '+mm+'/'+dd+'/'+yyyy); return today; } gives me an error that the onload function is expecting an object. Is ther something wrong with my coding? Hello, Wondering if any users could point me in the right direction on this one. Newbie question, how do I call up a local Var within a function? As you can see I have both a global and a local. but the doc.write will only show the global var. Code: <html> <head> <script type="text/javascript"> var p=0; function test(){ p=p+5; window.alert(p); } </script> </head> <body> <h1>test: <script type="text/javascript"> document.write(p); </script> </h1> <br> <input type="Button" value="Add" onclick="test()" /> </body> </html> Thanks in advance if anyone can help. Can anyone explain why this isn't working!? I hate JavaScript and dates! For the date: 07/08/2010 it will output: 6/7/2010. Thanks for any help. Code: var startDay = startDate.value.substr(0,2); var startMonth = startDate.value.substr(3,2); var startYear = startDate.value.substr(6,4); var myDate = new Date(startYear,startMonth-1,startDay+numberNights.value); endDate.value = myDate.getDay() + '/' + myDate.getMonth() + '/' + myDate.getFullYear(); Hi there How can you calculate the difference in two dates that are in different formats? I have one date as: '2010-06-16 21:20:44.000' and the other date as now = new Date(); I want to subtract the dates to see if it is over 30 days. Thanks! I'm not sure if java is the best way to go with this, I'm pretty inexperienced with java, but I have a workable knowledge of html, and couldn't see a way to do it that way... so here goes: For my job I work with a ton of different deadlines all the time. What I want to do is to make a webpage that displays the date N days ago, and N days into the future. So something like 7 days ago, 30 days ago, 60 days ago 75 days ago, 30 days from now, 60 days from now, 75 days from now. etc. I've found brief snippets for how to display today's date, but i'm having trouble with the calculations. Then I also need one that displays 18 years ago, I'm not sure if the change from days to years makes any kind of difference, but I suppose it's easy enough to convert years to days anyway.... How would I go about doing that? Thank you!!! .... [Edit] I have moved this thread to resolved since it cannot work the way I want it to (couldn't find a delete button). The variable in question is overwritten each time the function is called and there is no way to cache it globally. I will have to figure something else out for this one. Thank you to those that took a look anyway..... Ok, here is what I have. I am trying to fix up a calculator script that I found online to add a bit more intuitive function to it. I want to use this script but it irritates me the way it is. It's a simple enough script, which is why I want to use it, but I want to be able to use keyboard keys with it (instead of clicking buttons. Here's the HTML: Code: <FORM NAME="Calc"> <TABLE BORDER=4> <TR> <TD> <INPUT TYPE="text" NAME="Input" id="Input" Size="26"> <br> </TD> </TR> <TR> <TD> <INPUT TYPE="button" NAME="one" VALUE=" 1 " OnClick="Calc.Input.value += '1'"> <INPUT TYPE="button" NAME="two" VALUE=" 2 " OnCLick="Calc.Input.value += '2'"> <INPUT TYPE="button" NAME="three" VALUE=" 3 " OnClick="Calc.Input.value += '3'"> <INPUT TYPE="button" NAME="plus" VALUE=" + " OnClick="Calc.Input.value += ' + '"> <br> <INPUT TYPE="button" NAME="four" VALUE=" 4 " OnClick="Calc.Input.value += '4'"> <INPUT TYPE="button" NAME="five" VALUE=" 5 " OnCLick="Calc.Input.value += '5'"> <INPUT TYPE="button" NAME="six" VALUE=" 6 " OnClick="Calc.Input.value += '6'"> <INPUT TYPE="button" NAME="minus" VALUE=" - " OnClick="Calc.Input.value += ' - '"> <br> <INPUT TYPE="button" NAME="seven" VALUE=" 7 " OnClick="Calc.Input.value += '7'"> <INPUT TYPE="button" NAME="eight" VALUE=" 8 " OnCLick="Calc.Input.value += '8'"> <INPUT TYPE="button" NAME="nine" VALUE=" 9 " OnClick="Calc.Input.value += '9'"> <INPUT TYPE="button" NAME="times" VALUE=" x " OnClick="Calc.Input.value += ' * '"> <br> <INPUT TYPE="button" NAME="clear" VALUE=" C " OnClick="Calc.Input.value = ''"> <INPUT TYPE="button" NAME="zero" VALUE=" 0 " OnClick="Calc.Input.value += '0'"> <INPUT TYPE="button" NAME="DoIt" VALUE=" = " OnClick="Calc.Input.value = eval(Calc.Input.value)"> <INPUT TYPE="button" NAME="div" VALUE=" / " OnClick="Calc.Input.value += ' / '"> <br> </TD> </TR> </TABLE> </FORM> Now, what I am trying to fix is the fact that the enter key does not "emulate" the "=" sign button. I did some research and got the following KeyCode script: Code: document.onkeyup = KeyCheck; function KeyCheck(e) { if (document.Calc.Input.value != "") { var formVal = document.Calc.Input.value; } var KeyID = (window.event) ? event.keyCode : e.keyCode; if (KeyID == 13) { alert (formVal); document.getElementById("Input").value = eval(formVal); } } The only key I am concerned with is the enter key (code 13) so i figured I could just fire a statement when that key was detected, however my "formVal" variable seems to disappear after the first if statement. The reason for the first if statement is to keep the "fromVal" variable from being overwritten when the enter key is pressed. As it stands now, the alert box and the form input box display "undefined" when the enter key is pressed. What am I missing here? Hello, I am working on a project using HTML and javascript to allow the user to choose a vehicle from a drop down menu, then load a new page showing some information about this vehicle. The information is stored in an Excel file. I posted regarding this issue a while back and got an excellent response from Old Pedant (thanks again!) about using ActiveX - which has thus far worked perfectly. My initial condition was that I would only be using IE7+. However, my next idea was to be able to use it on an IPad (which I unfortunately do not own yet, making any kind of testing difficult) which I am fairly certain ActiveX won't work on. So, I was looking for any other method which would be similar. Important note: this will not use the internet at all, all of these files will be available locally. There is a lot of material on running queries to servers, but I didn't think that would really apply here. It seems pretty clear that JS has difficulty accessing files client side (which I understand why completely), but I was hoping to find something that worked for the gray zone I'm currently working in since I'm not using servers at all. I know that this is not really the intended use of HTML/JS, but I was hoping that by writing it as an HTML file, it'd be accessible to anyone with a browser. Some of my target computers have odd limitations (such as not being to download .exe files). The code I based my original off of is shown below: Code: <script type="text/javascript"> var conn = new ActiveXObject("ADODB.Connection") conn.Open ( 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\full\path\to\MyExcel.xls;Extended Properties="Excel 8.0;HDR=Yes;IMEX=1";)'; var sql = "SELECT * FROM [nameOfSheet$]"; var rs = conn.execute( sql ) while ( ! rs.eof ) { // just an example of dumping everything from the sheet out to the browser: for ( var f = 0; f < rs.fields.count; ++f ) { document.write( rs.fields(f).value + "," ); } document.write("<br>\n"); rs.moveNext(); } rs.close(); conn.close(); </script><script type="text/javascript"> var conn = new ActiveXObject("ADODB.Connection") conn.Open ( 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\full\path\to\MyExcel.xls;Extended Properties="Excel 8.0;HDR=Yes;IMEX=1";)'; var sql = "SELECT * FROM [nameOfSheet$]"; var rs = conn.execute( sql ) while ( ! rs.eof ) { // just an example of dumping everything from the sheet out to the browser: for ( var f = 0; f < rs.fields.count; ++f ) { document.write( rs.fields(f).value + "," ); } document.write("<br>\n"); rs.moveNext(); } rs.close(); conn.close(); </script> Thank you, klarosa Hi all. I have text area that includes the full path for a local file on our company network. The files are usually excel sheets or docs. How can I have it so when they clicks the file it opens the local file?
I run Windows 7 and IE9, and I believe IE9 supports HTML5 Local Storage. But when I run this offline (locally) in IE9 Code: <script type="text/javascript"> function testSupport() { if (localStorage) {return "Local Storage: Supported"} else { return "Local Storage: NOT supported"; } } alert ( testSupport() ); </script> I get "LocalStorage: NOT supported". Chrome returns "Local Storage: Supported" My DOCTYPE is <!DOCTYPE html> Other tests also fail in IE. Example: Code: localStorage.setItem("name", "Hello World!"); alert(localStorage.getItem("name")); Above works in Chrome. Any advice, please? Have I not configured IE9 properly? Hello, I am reading a block of code online and I don't understand why the output i in "Checking the value of: i " is always 5. Code: var someArray = [1,2,3,4,5], len = someArray.length, i = 0; var count = 0; for ( ; i < len; i++ ) { setTimeout(function() { console.log( count++ === i, 'Checking the value of: ' + i ); }, i * 300); } This will produce output below in console.log: Code: false Checking the value of: 5 false Checking the value of: 5 false Checking the value of: 5 false Checking the value of: 5 false Checking the value of: 5 The tutorial says the code will only render the final value in the sequence: 5 but not 1, 2, 3, 4, 5 as I would expect in the for loop. Could someone explain this to me. Thanks very much. Is there a best practice to get a lastmodified in local time vs. GMT? Here's the code: Code: var xmlhttp = new XMLHttpRequest(); xmlhttp.open("GET", "parks.xml", true); xmlhttp.send(); xmlhttp.onreadystatechange = function() { if(this.readyState == 2) { var updated = (xmlhttp.getResponseHeader("Last-Modified")); //alert(updated); document.getElementById('xml_modified').innerHTML = updated; } } Code: and <li id ="bottom_menu"><a href="parks.xml" target = "_blank">XML</a> Updated: <div id = "xml_modified"></li> Thanks for any help, S Not sure if this should be in the ASP forum or this one (probably could go either), so here goes. I don't know hardly any - probably best to say dont know any at all - javascript. However I have a need to convert some code from asp to js. the code is checking to see if certain variables are null and if so counting how many of those variables are as such. the ASP looks like this: Code: <% Dim counter counter = 0 if a <> "" then classcounter = classcounter + 1 if b <> "" then classcounter = classcounter + 1 if c <> "" then classcounter = classcounter + 1 if d <> "" then classcounter = classcounter + 1 if e <> "" then classcounter = classcounter + 1 if f <> "" then classcounter = classcounter + 1 %> I need to know how to convert this to js so I can show this number to the user without sending data to the server first. I have searched the net for something similar but I am not having much luck finding any examples that do what I would like it to do (maybe this is not something that can/should be done in js?). I hope this makes sense...thanks! I have 2 dates in variables (formatted like 'Wed Jan 18 2012 01:01:01 GMT+0000 (BST)') I need to minus them to get the days This worked if they were in the same month var amountOfDays = date.getDate() - datefirst.getDate(); However if the dates where in 2 different months it doesnt work. How would i do it better 2 months? Hello, I'd like to be able to calculate the difference between 2 dates in the format dd/mm/yyyy var date1 = 06/01/2012 var date2 = 10/01/2012 Then an alert box would tell me there is a difference of 4 days. Thanks a bunch Jay. Hi I have the following script Code: function timeDifference(laterdate,earlierdate) { var difference = laterdate.getTime() - earlierdate.getTime(); var daysDifference = Math.floor(difference/1000/60/60/24); difference -= daysDifference*1000*60*60*24 document.write('difference = ' + daysDifference + ' day/s '); } var laterdate = ? ; var earlierdate = ? ; timeDifference(laterdate,earlierdate); //--></script> and would like to insert my datein and dateout values where the ? marks are above in red. I can call these variables into the form on the page using <%=Request("datein")%> but how do I call a variable into the script above ? Thanks This is my problem: I have a seperate page on my website with a list of upcoming events. On that page I have the date of the upcoming event and then the description. On the main page of my website, I have a small table with the next four upcoming events(with the dates of course). So far I have been manually changing the four closest upcoming events on the main page. (just copy and paste from the upcoming events page) My question: Can javascript "grab" from the upcoming events page the next four events, and have them automatically pasted into the table on my main page? And if it is possible, what code(s) do I need? This way I don't have to do it manually and will save me lots of time. P.S. I have a weak understanding of javascript, but throw any code at me and I will try to understand it. Thank you Hi I'm relatively new to Javascript and I'm trying to learn more about dates my problem is as follows I have to do validation on a form for 2 dates(StartDate and EndDate) the dates cannot be more than four months apart if they are an alert must be displayed. In other words Nov 2009 till March 2010 or May 2009 till September 2009 should be invalid regardless of the day of the month Simply 2 input boxes(StartDate and EndDate) and a submit I've got the other parts of my page worked out just this has me stumped I would appreciate any help in this regard Thank You for your time I really don't understand JavaScript... xD Code: var inputDate = "<?php echo $inputDate2; ?>"; var JDates = new Array(); Jdates = inputDate.split("/"); var currentDate = new Date(parseInt(Jdates[2]), parseInt(Jdates[0])-1, parseInt(Jdates[1])); So... when creating 'currentDate' Jdates[0] will equal 0, even though I just asked javascript to split the inputDate by all "/". The inputDate var equals "08/06/2010" before the split. Any help greatly appreciated! Calculating the difference between two dates in JavaScript is relatively straightforward, provided you choose the right Date methods to work with. Whichever way you get there.... see this http://www.tutorials99.com/tutorials...aScript/page_1 Hi Guys I have created a flight/hotel itinerary and I need to work out the duration of the customers' holiday in order to work out how much it will cost to charge that person per night at their selected hotel. The problem I have is that the dates are going to vary due to user inputs in which I have used jquery 's " datepicker " Cheers George |