JavaScript - How Can I Add The Time To My Page Update?
I am using the following code to show visitors when my page was updated last.
It seems really cumbersome for what it does, too. Right now, it reads: Last updated on Monday, December 19, 2011 I wanted to add code to it so that it reads the hours and is in this format: Last updated on Monday, December 19, 2011 at 8:44am How can I add the "at hh:mm am/pm" part? Or is there easier code that will do this? Thank you in advance. Code: function getLongDateString() {month = new Array("January","February","March","April","May","June","July","August","September","October","November","December"); dayNames = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"); dayOfWeek = this.getDay(); day = dayNames[dayOfWeek]; dateOfMonth = this.getDate(); monthNo = this.getMonth(); month = month[monthNo]; year = this.getYear(); if (year < 2000) year = year + 1900; dateStr = day+", "+month+" "+dateOfMonth+", "+year; return dateStr; } //register the method in the class Date Date.prototype.getLongDateString=getLongDateString; function DocDate() { //return the document modification date (excl.time) //as a string DateTimeStr = document.lastModified; secOffset = Date.parse(DateTimeStr); if (secOffset == 0 || secOffset == null) //Opera3.2 dateStr = "Unknown"; else { aDate = new Date(); aDate.setTime(secOffset); //use method defined above datestr = aDate.getLongDateString(); } return dateStr; } document.write("<left> Last updated on "); document.writeln(DocDate(),"</left>"); Similar TutorialsHi, I have this PHP code that shows the amount of minutes and seconds to a certain date. Somehow I want to update this code every second so that it looks like it's counting down. Anyone who has any good pointers how to do this? Thank you in advance. OK, I've just been working with kwyl, trying to intergrate a like/dislike script to her site. There was an original script, and although bugged, it's almost the What works The user clicks the like/dislike icon. Ajax sends a request to PHP: Either the like/dislike gets inserted into the database. OR, if the user has already liked/disliked that post, an alert error gets returned. What doesn't work If you click to like/dislike a post, it won't appear (the current count is in brackets beside the icons) unless the page is refreshed. How would I use this along side Ajax for auto update? $data = mysql_fetch_object(mysql_query('SELECT `like`,`unlike` FROM posts WHERE id="'.$row['id'].'"')); It's used he Code: $data = mysql_fetch_object(mysql_query('SELECT `like`,`unlike` FROM posts WHERE id="'.$row['id'].'"')); ?> <br /> <div class="vote"> <a href="javascript:;" onclick="doAction('<?php echo $row['id']; ?>','unlike');"> <input type="image" name="submit" src="images/down.gif" /></a> (<span id=""><?php echo $data->unlike;?></span>) <a href="javascript:;" onclick="doAction('<?php echo $row['id']; ?>','like');"> <input type="image" name="submit" src="images/up.gif"></a> (<span id=""><?php echo $data->like;?></span>) I hate javascript and this is utterly driving me up the wall. Any help would be much appreciated. If you need more informaton/code please ask. hi the title pretty much says it but il go into a little more deph, im looking for a piece of script that i can insert into my masterpage which will fetch the year from the server and display it on the footer. just to save our company updating the dates each year. cheers, ant. Hi, ive been asked to make a blackjack game in javascript but I have a little bit of a problem. When the page loads, it deals cards to the player and the dealer, showing which cards have been dealt and the current scores. When I press the HIT button, i need to add another card to the array player_hand_img, and the value of this card to player_hand. I have successfully created this code, but my question is, how do I update the information (the score and the cards) on the screen after it has loaded? Can you do this in JavaScript or do I need another language? Thanks very much in advance! Hello Friends In my jsp,Struts project i am using the javascript calendar control for selecting the date and by using function calcage() i am calculating the age of the user but problem occurs when the page refreshes OR when user updated the other values such as name ,contact no. Then the value of the age is set as 0 in the textfield as 0 So can you please tell me why this problem occurs And please give me solution Thanks I've seen a few people elsewhere with a similar problem, but couldn't get the solutions to work for my individual problems. I am currently trying to display a gallery of images using Lightbox, and a contact form in a different modal window using a different script. Here is the URL, so you can view the source. Clicking 'contact' opens the Contact window, which currently works, and clicking the images SHOULD open lightbox but doesn't. If I shuffle the code around, I can get Lightbox to work but the contact window then breaks. If someone could provide just the code I should replace mine with so I can just copy and paste it in, that would be great because I don't know anything about javascript and struggled to follow the instructions for this I found elsewhere. However any help is appreciated! Thanks in advance. (: (Just in case you notice - please excuse my use of tables in the coding, this is just temporary) This may be a stupid question, but is there a way to have a page refreshed at a specific time of day? I have made up a page I set as my browser's home page, an electronic Page-A-Day calendar. If I am working on the computer overnight I would like this page to refresh autotically at midnight. I have seen all sorts of posts that describe how to refresh after a certain amount of time has passed, but nothing for what I would like to do. For those interested the code i have for the webpage in in the attached file. Nite I've a web page when a user logs in, it will have a link that shows the "username" and a link for "logout". After the user logs out, the "username" and the "logout" links will change to "login" and "register" links, respectively. The page uses javascript to check a user cookie, if the user cookie exists, it will show the "username" link and the link for "logout". If no user cookie exists, "login" and "register" links will replace the "username" and "logout" links. Here's the problem: When a user who has log in, clicks the "logout" link, a perl script will delete the user cookie, and redirects back to the same page. The page does not show "login" and "register" links AUTOMATICALLY. Both links will appear ONLY after the user MANUALLY Refreshes the page. It appears that I need a system to refresh the page automacally ONLY one time. How can this be done? I am current building an information database for the company I work at...basically just a place for employees to get information and answers from. It is all hosted on a local server and I can only use javascript, html, and css. Ive got everything made there is just one thing i want to add to it. basically an "alerts and updates" page that only some people can edit without having to know html so if im not there they can post important updates. no computers have access to the internet so I did try some rich text editors but none of them worked. the lay out I'm going for is kind of like this. ------------------------------------ Alerts and Updates Click on links to show updates: update 1 * update 2 * update 3 * update 4 stuff goes in the update [edit button] ------------------------------------- you click edit it prompts you to login, bring up something to edit the text in that specific update you hit submit and it changes the info that was on there. The update links are linked to a script i wrote that just display the info below so when the page loads you see whats in update 1 then you click update and it changes the content to the next one. i dont know if there is any way to do this in javascript and html. any help or a good direction to start would be great...thanks. how can i make a button disable when the page is loaded first time and then make it enable on the click of other button in javascript.
I am try to reduce the time taken to download my home page. I purchased a template and then just modified what I wanted. There is a script that calls 21 other scripts. I am told if I combined all this scripts into one or two scripts, my download time would go down. Help appreciated. Drachsi www.drachsi.com hi im using dhtml xgrid where i need to do validation for time ,(from-time and to-time i.e ind==1 and ind==2 ) to-time must be greater than from-time else i need to alert a message to-time must be greater than from-time. can any one send me the code for it time format is[05:00]. Code: var err_str=""; function validate_grid(value,id,ind) { $("#result").html(" ").show(); if(ind==1 || ind==2) { var patt=/^([0][0-9]|[1][0-9]|[2][0-3])[:]{1}[0-5][0-9]$/; if(!patt.test(value)) { mygrid.setCellTextStyle(id,ind,"background-color:yellow;"); if(err_str!="") err_str+="\n"+(ind+1)+".Enter numbers and : only.."; else err_str=(ind+1)+".Enter numbers and : only"; return false; } else { mygrid.setCellTextStyle(id,ind,"background-color:white;"); return true; } } } Hi Code: var err_str=""; function validate_grid(value,id,ind) { $("#result").html(" ").show(); if(ind==1 || ind==2) { var patt=/^([0][0-9]|[1][0-9]|[2][0-3])[:]{1}[0-5][0-9]$/; if(!patt.test(value)) { mygrid.setCellTextStyle(id,ind,"background-color:yellow;"); if(err_str!="") err_str+="\n"+(ind+1)+".Enter numbers and : only.."; else err_str=(ind+1)+".Enter numbers and : only"; return false; } else { mygrid.setCellTextStyle(id,ind,"background-color:white;"); return true; } } } alert(err-str); here ind==1 is from_time and ind==2 is to_time,i need to validate time as to_time must be always greater than from-time,if condition fails an alert msg should populate.time format is[05:00]as it is in string format im unable to do the validation for it.(ex:from-time=08:00 to-time=07:59 condition fails) thank you. Hello im using dhtmlx grid in this cells i have from time and to time (i.e ind==1 and ind==2) i need to validate time where to-time must be greater than from-time else it should alert an message,i have writeen a normal Regular expression for the time validation.as the time is i string format i.e[05:00],please can any one send me code for that. Code: var err_str=""; function validate_grid(value,id,ind) { if(ind==1 || ind==2) { var patt=/^([0][0-9]|[1][0-9]|[2][0-3])[:]{1}[0-5][0-9]$/; if(!patt.test(value)) { mygrid.setCellTextStyle(id,ind,"background-color:yellow;"); if(err_str!="") err_str+="\n"+(ind+1)+".Enter numbers and : only.."; else err_str=(ind+1)+".Enter numbers and : only"; return false; } else { mygrid.setCellTextStyle(id,ind,"background-color:white;"); return true; } } } 1 down vote favorite I do have the countdown script (see link below) to display the time between current time and the date given in real-time. However, I want to achieve to display the time difference between a given start and end time. Right now, it calculates from the current server time to the end time. I want to be able to set up my own start time and end time. Here is what I have: http://jsfiddle.net/BgEtE/ thank you for help I'm not really a Java writer, so I don't know how to do this myself, though I imagine it would be pretty simple. I am looking to add a script to a webpage that allows users to input a time manually, and have it converted to GMT/Zulu time and display the converted time. I have seen a lot of time zone conversion scripts online, but they all just convert whatever the current system time is to another time zone. I am looking for a script that allows users to convert a time and show the zulu time, for times other than the current time. The time zone the inputed local time would be in is +4:30 (Kabul). I don't really care about style or aestehtics, just a simple script I can insert into a web page to have a time input field. The converted output time can appear in another field, a popup bubble, etc, again style isn't really an issue. It's really just to help people in my job who need to know what the GMT/Zulu time was for certain local times after the fact. One would think it shouldn't be that hard to just subtract 4:30 in your head, but apparently it is. Sorry if just asking for code outright like this is frowned upon. hi, can some one help me how to get the time and date difference? given two time and date with the following format like in textbox A: 2011-05-03 17:35:47.0 and textbox B: 2011-05-03 16:35:47.0 then the output would be: 0 days, 1 hour, 0 minutes, 0 seconds regards, verve This is my first time doing JavaScript I don't what I did wrong here, but the problem its not showing up the current date and time. Code: <script language = "JavaScript" type="text/javascript"> now = new Date(); localtime = now.toString(); utctime = now.GMTString(); document.wite("<b>localtime</b>" + localtime + "</br>"); document.write("<b>utctime</b>" + utctime); </script> This is what supposed to look like I have tried using different browser chrome,IE9,Maxtor, and Opera my OS is Win7 Hi - I have a date in my javascript like this: Mon Dec 12 00:00:00 UTC+0430 2011 I need to convert it to a date without the offset (the +0430). I actually changed my computer's timezone to generate this offset - we have uses placing orders on our site who don't use UTC and it's throwing our orders out as they need to select a delivery date but it's passing the date with the offset. How do I convert a date to UTC time? Thanks Hi there! Well, I recently found the Image clock code, and I am loving it! But, I would like it to only display pacific time, not retrieve the time from a users browser. Here's my code: Code: <script type="text/javascript"> /*********************************************** * JavaScript Image Clock- by JavaScript Kit (www.javascriptkit.com) * This notice must stay intact for usage * Visit JavaScript Kit at http://www.javascriptkit.com/ for this script and 100s more ***********************************************/ var imageclock=new Object() //Enter path to clock digit images here, in order of 0-9, then "am/pm", then colon image: imageclock.digits=["/users/1712/49/18/66/album/c012.png", "/users/1712/49/18/66/album/c112.png", "/users/1712/49/18/66/album/c211.png", "/users/1712/49/18/66/album/c311.png", "/users/1712/49/18/66/album/c411.png", "/users/1712/49/18/66/album/c511.png", "/users/1712/49/18/66/album/c611.png", "/users/1712/49/18/66/album/c711.png", "/users/1712/49/18/66/album/c811.png", "/users/1712/49/18/66/album/c911.png", "/users/1712/49/18/66/album/cam11.png", "/users/1712/49/18/66/album/cpm13.png", "/users/1712/49/18/66/album/ccolon11.png"] imageclock.instances=0 var preloadimages=[] for (var i=0; i<imageclock.digits.length; i++){ //preload images preloadimages[i]=new Image() preloadimages[i].src=imageclock.digits[i] } imageclock.imageHTML=function(timestring){ //return timestring (ie: 1:56:38) into string of images instead var sections=timestring.split(":") if (sections[0]=="0") //If hour field is 0 (aka 12 AM) sections[0]="12" else if (sections[0]>=13) sections[0]=sections[0]-12+"" for (var i=0; i<sections.length; i++){ if (sections[i].length==1) sections[i]='<img src="'+imageclock.digits[0]+'" />'+'<img src="'+imageclock.digits[parseInt(sections[i])]+'" />' else sections[i]='<img src="'+imageclock.digits[parseInt(sections[i].charAt(0))]+'" />'+'<img src="'+imageclock.digits[parseInt(sections[i].charAt(1))]+'" />' } return sections[0]+'<img src="'+imageclock.digits[12]+'" />'+sections[1]+'<img src="'+imageclock.digits[12]+'" />'+sections[2] } imageclock.display=function(){ var clockinstance=this this.spanid="clockspan"+(imageclock.instances++) document.write('<span id="'+this.spanid+'"></span>') this.update() setInterval(function(){clockinstance.update()}, 1000) } imageclock.display.prototype.update=function(){ var dateobj=new Date() var currenttime=dateobj.getHours()+":"+dateobj.getMinutes()+":"+dateobj.getSeconds() //create time string var currenttimeHTML=imageclock.imageHTML(currenttime)+'<img src="'+((dateobj.getHours()>=12)? imageclock.digits[11] : imageclock.digits[10])+'" />' document.getElementById(this.spanid).innerHTML=currenttimeHTML } </script> <DIV STYLE="position:absolute; top:260px; left:215px; width:109px; height:28px"> <FONT SIZE="+2" COLOR="black"> <TABLE BORDER="0" cellpadding="10" CELLSPACING="0" TOP MARGIN="0"> <TR> <TD WIDTH="109" HEIGHT="28" BACKGROUND="/users/1712/49/18/66/album/clock210.png" VALIGN="top"> <script type="text/javascript"> new imageclock.display() </script> </TD> </TR> </TABLE> </DIV> Much appreciated! |