php - How to add day on this js time script? -


this js/php displaying function:

    <script type="text/javascript">         $.fn.cycle.defaults.speed   = 900;         $.fn.cycle.defaults.timeout = 5000;          $(function()          {             $('#demos pre code').each(function()              {                 eval($(this).text());             });              $('#demos2 pre code').each(function()              {                 eval($(this).text());             });         });          $(function($) {           var pstoptions = {             timenotation: '12h',             am_pm: true,             utc: true,             utc_offset: <%setting_timeoffset%>,             fontfamily: 'verdana, times new roman',             fontsize: '11px',             foreground: 'white',              background: 'black'           }           $('.jclockpst').jclock(pstoptions);         });     </script> 

and full js script:

/*  * jquery jclock - clock plugin - v 0.2.1  * http://plugins.jquery.com/project/jclock  *  * copyright (c) 2007-2008 doug sparling <http://www.dougsparling.com>  * licensed under mit license:  *   http://www.opensource.org/licenses/mit-license.php  */ (function($) {    $.fn.jclock = function(options) {     var version = '0.2.1';      // options     var opts = $.extend({}, $.fn.jclock.defaults, options);      return this.each(function() {       $this = $(this);       $this.timerid = null;       $this.running = false;        $.fn.jclock.getserveroffset($this);        var o = $.meta ? $.extend({}, opts, $this.data()) : opts;        $this.timenotation = o.timenotation;       $this.am_pm = o.am_pm;       $this.utc = o.utc;       $this.utc_offset = o.utc_offset;        $this.css({         fontfamily: o.fontfamily,         fontsize: o.fontsize,         backgroundcolor: o.background,         color: o.foreground       });        $.fn.jclock.startclock($this);      });   };    $.fn.jclock.getserveroffset = function(el) {     //want make synchronous call server server time.     $.ajax({         url: "time.php",         async: false,         context: el,         success: function(result) {             var serverdate = new date(+(result) * 1000); //convert seconds number, , multiple 1000 milliseconds.             var clientdate = new date();              $this = $(this.context[0]);              $this.serveroffset = clientdate - serverdate; //set offset between server , client.         }     });   };    $.fn.jclock.startclock = function(el) {     $.fn.jclock.stopclock(el);     $.fn.jclock.displaytime(el);   };    $.fn.jclock.stopclock = function(el) {     if(el.running) {       cleartimeout(el.timerid);     }     el.running = false;   };    $.fn.jclock.displaytime = function(el) {     var time = $.fn.jclock.gettime(el);     el.html(time);     el.timerid = settimeout(function(){$.fn.jclock.displaytime(el)},1000);   };    $.fn.jclock.gettime = function(el) {       var = new date(new date().gettime() - el.serveroffset); //apply server offset.     var hours, minutes, seconds;      if(el.utc == true) {       if(el.utc_offset != 0) {         now.setutchours(now.getutchours()+el.utc_offset);       }       hours = now.getutchours();       minutes = now.getutcminutes();       seconds = now.getutcseconds();     } else {       hours = now.gethours();       minutes = now.getminutes();       seconds = now.getseconds();     }      var am_pm_text = '';     (hours >= 12) ? am_pm_text = " p.m." : am_pm_text = " a.m.";      if (el.timenotation == '12h') {       hours = ((hours > 12) ? hours - 12 : hours);     } else {       hours   = ((hours <  10) ? "0" : "") + hours;     }      minutes = ((minutes <  10) ? "0" : "") + minutes;     seconds = ((seconds <  10) ? "0" : "") + seconds;      var timenow = hours + ":" + minutes + ":" + seconds;     if ( (el.timenotation == '12h') && (el.am_pm == true) ) {      timenow += am_pm_text;     }      return timenow;   };    // plugin defaults   $.fn.jclock.defaults = {     timenotation: '24h',     am_pm: false,     utc: false,     fontfamily: '',     fontsize: '',     foreground: '',     background: '',     utc_offset: 0   };  })(jquery); 

how add date on it, display monday, tuesday , etc ? current time obtained via time.php via echo time();

thanks lot, appreciated.

you can use date object's getday() method achieve this. getday() method return 0 ( sunday ) 6 ( saturday ).

you need build array first:

var wdays = [ 'sunday', 'monday',  ... , 'saturday'] ; 

then week day name :

var weekday = wdays[now.getday()];  timenow += weekday; //append week day final result 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -