March 28, 2024, 05:22:53 am
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Welcome to Revolution X, where Coding meets Graphics.
 
  Home Help Search Arcade Affiliates Staff List Calendar Members Login Register  

Auto-Update the Time

Pages: [1]   Go Down
  Print  
Author Topic: Auto-Update the Time  (Read 1409 times)
0 Members and 1 Guest are viewing this topic.
Celebrus
Artificially Conscious
Administrator
Adminitrator
Offline Offline

Gender: Male
Posts: 626



View Profile WWW
Badges: (View All)
Apple User
« on: April 30, 2009, 02:01:17 am »

Preview: http://celebrusisawesome.smfforfree.com/

Has been tested on Firefox, Epiphany and Opera.

First ensure you have this in your headers:
Code:
<script src="/jquery.js" type="text/javascript"></script>

If you have that, proceed. If you don't, add it and return.

Then stick this in your footers:
Code:
<script type="text/javascript">
/**
 * Auto-Update the Time
 * http://aetus.net/
 * http://revolutionx.smfforfree3.com/
 *
 *  While there is NO warranty on this script unless you pay me a very large fee,  I will *TRY*
 *  to the best of my ability to help you out.
 *
 *  License: WTFPL (http://sam.zoy.org/wtfpl/)
 *  
 *  Feel free to remove this copyright notice, just visit those two sites listed above.
 *  Thanks for using this script.
 *
 */
function getTimeString() {
  var t = new Date();
  var months = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July',
  'August', 'September', 'October', 'November', 'December' ];
  var month = months[t.getMonth()];
  var date = t.getDate();
  var year = t.getFullYear();
  var hour = t.getHours();
  var suffix = "am";
  if (hour >= 12) {
    suffix = "pm";
    hour = (hour == 12) ? "12" : hour - 12;
  }
  if(hour < 10) { hour = "0" + hour; } 
  var minute = t.getMinutes();
  if(minute < 10) { minute = "0" + minute; }
  var second = t.getSeconds();
  if(second < 10) { second = "0" + second; }
  return month + " " + date + ", " + year + ", " + hour + ":" + minute + ":" + second + " " + suffix;
}
function updateTheDate($) {
  var timeString = getTimeString();
  var timeDisplay = $("div.tborder table tbody tr td.titlebg2 span.smalltext:contains(pm)");
  if(timeDisplay.length === 0) {
    timeDisplay = $("div.tborder table tbody tr td.titlebg2 span.smalltext:contains(am)");
  }
  timeDisplay.html(timeString);
}
setInterval("updateTheDate(jQuery)", 1000);
</script>

And voila, you now have a clock that shows the time *right now*, not when the page was loaded. And the time is from the user's computer, so you (and your members) don't have to mess with time offsets.
« Last Edit: May 03, 2009, 11:41:46 pm by Celebrus » Report Spam   Logged

Share on Facebook Share on Twitter

Agent Moose
Administrator
Adminitrator
Offline Offline

Gender: Male
Posts: 1,470



View Profile WWW
Badges: (View All)
Tenth year Anniversary Nineth year Anniversary Search
« Reply #1 on: April 30, 2009, 07:56:48 am »

Nice code Cele.  Havn't seen a code from you that is javascript in forever Smiley
Report Spam   Logged


Exilis
Optimistic & Creative
Global Moderator
Global Moderator
Offline Offline

Posts: 929


View Profile
Badges: (View All)
Tenth year Anniversary Linux User Combination
« Reply #2 on: April 30, 2009, 03:52:45 pm »

Cool... But it's showing me 24 hour time, and it still says PM.
Report Spam   Logged

Global Mod, (sort of) at your service.

http://twitter.com/timothyaveni

Celebrus
Artificially Conscious
Administrator
Adminitrator
Offline Offline

Gender: Male
Posts: 626



View Profile WWW
Badges: (View All)
Apple User
« Reply #3 on: May 01, 2009, 12:08:23 am »

Weird, this line is supposed to fix that:
    hour = (hour == 0) ? hour - 12 : "12";
Report Spam   Logged

Exilis
Optimistic & Creative
Global Moderator
Global Moderator
Offline Offline

Posts: 929


View Profile
Badges: (View All)
Tenth year Anniversary Linux User Combination
« Reply #4 on: May 01, 2009, 06:09:11 am »

That's weird- It wasn't twenty-hour time... It couldn't have been, because it was 4:50 for me. The clock said 12:50 o.O
Let me try the preview again...

EDIT: W00T I didn't even notice- I'm a hero member on RX- Well, I would be if the membergroups weren't changed on here...
Report Spam   Logged

Global Mod, (sort of) at your service.

http://twitter.com/timothyaveni

Celebrus
Artificially Conscious
Administrator
Adminitrator
Offline Offline

Gender: Male
Posts: 626



View Profile WWW
Badges: (View All)
Apple User
« Reply #5 on: May 01, 2009, 06:13:15 am »

Ok there is that problem. I'm fixing it!
Report Spam   Logged

Exilis
Optimistic & Creative
Global Moderator
Global Moderator
Offline Offline

Posts: 929


View Profile
Badges: (View All)
Tenth year Anniversary Linux User Combination
« Reply #6 on: May 01, 2009, 06:17:10 am »

Weird. Works now. Thanks!
Report Spam   Logged

Global Mod, (sort of) at your service.

http://twitter.com/timothyaveni

Celebrus
Artificially Conscious
Administrator
Adminitrator
Offline Offline

Gender: Male
Posts: 626



View Profile WWW
Badges: (View All)
Apple User
« Reply #7 on: May 01, 2009, 06:20:00 am »

Weird. Works now. Thanks!

That's because I just fixed it. I still have to see what happens when the hour is 12...
Report Spam   Logged

Blighted
Blighted Mega Forums Owner
Newcomers!
Newcomers!
Offline Offline

Gender: Male
Posts: 8


View Profile WWW
Badges: (View All)
« Reply #8 on: May 20, 2009, 01:28:14 pm »

great I've been fed up with having to put up with dodgy forum times thanks celebrus
Report Spam   Logged
Lyle
MeTube
Member
Member
Offline Offline

Gender: Male
Posts: 69



View Profile
Badges: (View All)
« Reply #9 on: June 07, 2009, 04:03:19 pm »

this is cool, but doesnt the time update by itself anyways/.?
Report Spam   Logged
Agent Moose
Administrator
Adminitrator
Offline Offline

Gender: Male
Posts: 1,470



View Profile WWW
Badges: (View All)
Tenth year Anniversary Nineth year Anniversary Search
« Reply #10 on: June 07, 2009, 05:04:08 pm »

It does, but this one makes it in Real Time.  So it will change every second.
Report Spam   Logged


Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum

Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy