RSS | Archive | Random | E-mail

About

Hi, I'm Christian Castelli, a 28 years old italian programmer located in Pisa (Italy). Here I post small snippets of code which can be useful in my work.

Links

Codepuzzling main site
Development site
ByteStrike italian blog
Follow me on Twitter

My Life Style

while(passion) {
  try {
    myLife.run();
  }catch(LifeExceptions) {  
    stronger++;
    continue;
   }
}

Following

22 September 09

[JS] How to get the time and unixtime

Self explanatory code:

var T = {
 getUnixTime: function() {
   return parseInt(new Date().getTime().toString().substring(0, 10));
 },
	
// format hh:mm:ss
getTime: function() 
{
  var d= new Date();
  var time = new Array();
  var hours = d.getHours();
  time.push(hours);
  var minutes = d.getMinutes().toString().length < 2 ? "0"+d.getMinutes() : d.getMinutes(); 
  time.push(minutes);
  var seconds = d.getSeconds().toString().length < 2 ? "0"+d.getSeconds() : d.getSeconds(); 
  time.push(seconds);
  	
  return time.join(":");
 }
}	
Update: I’ve just discovered that Syntax Highlighter code doesn’t work well with < > symbols in javascript code….

Comments (View)
  1. codepuzzling posted this
blog comments powered by Disqus
Themed by Hunson. Originally by Josh