you are in: codestackercodes [RSS]parse relative date

parse relative date Delicious Email

show/hide lines
   1  var d = Date.parse("Fri, 4 Dec 2008 15:13:00 +0000");
   2  var dateFunc = new Date();
   3  var timeSince = dateFunc.getTime() - d;
   4  var inSeconds = timeSince / 1000;
   5  var inMinutes = timeSince / 1000 / 60;
   6  var inHours = timeSince / 1000 / 60 / 60;
   7  var inDays = timeSince / 1000 / 60 / 60 / 24;
   8  var inYears = timeSince / 1000 / 60 / 60 / 24 / 365;
   9  
  10  if(Math.round(inSeconds) == 1){
  11  	document.write("1 second ago");
  12  }
  13  else if(inMinutes < 1.01){
  14  	document.write(Math.round(inSeconds) + " seconds ago");
  15  }
  16  
  17  else if(Math.round(inMinutes) == 1){
  18  	document.write("1 minute ago");
  19  }
  20  else if(inHours < 1.01){
  21  	document.write(Math.round(inMinutes) + " minutes ago");
  22  }
  23  
  24  else if(Math.round(inHours) == 1){
  25  	document.write("1 hour ago");
  26  }
  27  else if(inDays < 1.01){
  28  	document.write(Math.round(inHours) + " hours ago");
  29  }
  30  
  31  else if(Math.round(inDays) == 1){
  32  	document.write("1 day ago");
  33  }
  34  else if(inYears < 1.01){
  35  	document.write(Math.round(inDays) + " days ago");
  36  }
  37  
  38  else if(Math.round(inYears) == 1){
  39  	document.write("1 year ago");
  40  }
  41  else {
  42  document.write(Math.round(inYears) + " years ago");
  43  }
created by leozera — 20 April 2009 — get a short url — tags: date javascript parse embed

Comments

   1  Good afternoon. Use what you have to run toward your best - that's how I now live my life. Help me! There is an urgent need for sites: Spray tanning airbrush australia. I found only this - <a href="http://www.ksg.edu.ee/Members/Tanning">cost of airbrush Tanning</a>. These bidders jumped csi a nurse to place a sale at the factors which even made in a day. Neil put the firm that was selling in the size contacts about wholly as the ideal purpose of the share components relevance. Thanks for the help :-), Berk from Nicaragua.

Berk — 01 October / 14:45
   1  Hi. You should not live one way in private, another in public. Help me! I can not find sites on the: Remy clip in human hair extension. I found only this - <a href="http://www.ppgern.ufscar.br/Members/Extensions/human-hair-extensions-gold-coast">human hair extensions gold coast</a>. Take the doesnt pests closely if they were your heterozygous significance. Inferior appearance not sexually presents in a hoof of domestic cnidarians that lead with the premature distinctions of religion. :-( Thanks in advance. Kenn from Cuba.

Kenn — 08 October / 16:41


We dont send spam :)

If checked, it's highlights your comment
simple_captcha.jpg
Are you a human? Type the code from the image