1

I KNOW that this is basic. But I'm so JS-retarded I can't "do-it-myself" and I'm tired of spending hours getting nowhere. Please help!

There are dozens of JS countdowns I find by Googling & on jQuery.org. The one I'm trying to modify is http://plugins.jquery.com/project/tgcCountdown because it's the kind of BASIC counter I need. But it only offers the countdown based on a given SQL timestamp, and I need a 2nd option of a fixed timer, e.g. 5 minutes from NOW.

Any advice? I know it's gotta be simple! secs = 300 or now.getTime() + 300 or something like that! I'm so close but I just can't get there!

bdukes
  • 152,002
  • 23
  • 148
  • 175
Daniel Fowler
  • 385
  • 7
  • 21

1 Answers1

1
// Using http://phrogz.net/JS/FormatDateTime_JS.txt
var fiveMinutesFromNow = new Date( (new Date)*1 + 1000 * 60 * 5 );
var timestamp = fiveMinutesFromNow.customFormat( '#YYYY##MM##DD##hhh##mm##ss#' );
console.log( timestamp );
// "20110207122917"

Edit to work for Firefox

Phrogz
  • 296,393
  • 112
  • 651
  • 745
  • Try that in the console: "Invalid Date" – bdukes Feb 07 '11 at 19:18
  • Firefox/firebug. `new Date( new Date + 5 )` gets me five minutes from now – bdukes Feb 07 '11 at 19:20
  • @bdukes How odd of FF to do that; fixed; note that `+ 5` will only get you 5ms in the future on Chrome. – Phrogz Feb 07 '11 at 19:21
  • Thanks for this, very very helpful - especially the TXT file you reference in the commented portion of your script! I'm struggling to stop the countdown prematurely. Is there an easy way to do this? For example: `$('#stop').click(function() {countdownStop()});` – Daniel Fowler Jun 14 '11 at 21:13