date round

by priyanka tiwari

HTML

<input id="foo" name="foo" type="text" value="" size="55" />

JavaScript

jQuery(document).ready(function() {
    var foo = jQuery('#foo');
  
    function updateTime() {
        var now = new Date(),
            d = [];
            
        d[0] = now.getFullYear().toString(),
        d[1] = now.getMonth()+1, //months are 0-based
        d[2] = now.getDate(),
        d[3] = now.getHours(),
        d[4] = Math.ceil(now.getMinutes()/5)*5;
        
        d[0] = d[0].substring(d[0].length-2); 
        for (var i=1; i<=4; i++)
            if (d[i] < 10) d[i] = '0' + d[i];

        foo.val(d[0] + '-' + d[1] + '-' + d[2] + ' ' + d[3] + ':' + d[4]);
    }
  
    updateTime();
    setInterval(updateTime, 5000);
});