Javascript 如何将代码更改为我自己的国家时区? 函数timeleft(eventTime){ var now=新日期(); var now_utc=新日期(now.getUTCFullYear()、now.getUTCMonth()、now.getUTCDate()、now.getUTCHours()、now.getUTCMinutes()、now.getUTCSeconds()); var event_time=新日期(eventTime); var t1=now_utc.getTime(); //从日期中删除一小时-60分钟*60秒*1000毫秒--60*60*1000 var t2=event_time.getTime(); var time_left=新日期(parseInt(t2-t1)); 如果(左时间=0) { elem=jQuery(“”).css({ 高度:options.digithweight*options.digitmages*10, float:'left',background:'url(\''+options.image+'\'), 宽度:options.digitWidth}); 数字推送(elem); 边距(c,-((parseInt(tempStartTime.charAt(i))*options.digithweight* 选项(数字图像); 数字[c]。uu max=9; //添加最大位数,例如,分钟的第一位数(mm)为 //最大值为5。当左位数达到时,使用条件最大值 //例如,第二个“小时”数字的最大值为3 开关(选项.格式.字符(i)){ 案例“h”: 数字[c]。uu max=(c%2==0)?2:9; 如果(c%2!=0) 数字[c]。uu condmax=3; 打破 案例“d”: 数字[c]。uu max=9; 打破 案例“m”: 案例s: 数字[c]。uu max=(c%2==0)?5:9; } ++c; } 其他的 elem=jQuery(“”).css({float:'left'}) .text(options.format.charAt(i-1)); 其中。附加(“”); 其中。追加(elem); 其中。附加(“”); } elem=jQuery(“”).css({float:'left'}) .文本('s'); 其中。附加(“”); 其中。追加(elem); 其中。附加(“”); }; //设置或获取元素边距 var保证金=功能(要素,val) { 如果(val!==未定义) 返回数字[elem].css({'marginTop':val+'px'}); 返回parseInt(数字[elem].css('marginTop')。替换('px',''); }; //做这个动作。这是通过“数字图像”步骤完成的。 var moveStep=功能(元素) { 数字[elem]。_digitiinitial=-(数字[elem]。_max*options.digithweight*options.digitImages); 返回函数_move(){ mtop=边距(元素)+options.digithweight; if(mtop==options.digithweight){ 边距(元素,数字[元素]。_digitInitial); 如果(elem>0)移动步骤(elem-1)(); 其他的 { 间隔时间; 对于(var i=0;i0)和&(数字[elem]。uu condmax!==未定义)& (数字[elem-1]。_digitiinitial==边距(elem-1))) 边距(elem,-(数字[elem].\uu condmax*options.digithweight*options.digitImages)); 返回; } 保证金(要素、mtop); if(边距(元素)/options.digithweight%options.digitImages!=0) setTimeout(_move,options.stepTime); 如果(mtop==0)位[elem]。\uu ismax=true; } }; extend(options,userOptions); css({height:options.digithweight,overflow:'hidden'}); createDigits(sct_div_id); 间隔=设置间隔(移动步长(位数.length-1),1000); } 函数timeleft(eventTime){ var now=新日期(); var now_utc=新日期(now.getUTCFullYear()、now.getUTCMonth()、now.getUTCDate()、now.getUTCHours()、now.getUTCMinutes()、now.getUTCSeconds()); var event_time=新日期(eventTime); var t1=now_utc.getTime(); //从日期中删除一小时-60分钟*60秒*1000毫秒--60*60*1000 var t2=event_time.getTime(); var time_left=新日期(parseInt(t2-t1)); if(time_left

Javascript 如何将代码更改为我自己的国家时区? 函数timeleft(eventTime){ var now=新日期(); var now_utc=新日期(now.getUTCFullYear()、now.getUTCMonth()、now.getUTCDate()、now.getUTCHours()、now.getUTCMinutes()、now.getUTCSeconds()); var event_time=新日期(eventTime); var t1=now_utc.getTime(); //从日期中删除一小时-60分钟*60秒*1000毫秒--60*60*1000 var t2=event_time.getTime(); var time_left=新日期(parseInt(t2-t1)); 如果(左时间=0) { elem=jQuery(“”).css({ 高度:options.digithweight*options.digitmages*10, float:'left',background:'url(\''+options.image+'\'), 宽度:options.digitWidth}); 数字推送(elem); 边距(c,-((parseInt(tempStartTime.charAt(i))*options.digithweight* 选项(数字图像); 数字[c]。uu max=9; //添加最大位数,例如,分钟的第一位数(mm)为 //最大值为5。当左位数达到时,使用条件最大值 //例如,第二个“小时”数字的最大值为3 开关(选项.格式.字符(i)){ 案例“h”: 数字[c]。uu max=(c%2==0)?2:9; 如果(c%2!=0) 数字[c]。uu condmax=3; 打破 案例“d”: 数字[c]。uu max=9; 打破 案例“m”: 案例s: 数字[c]。uu max=(c%2==0)?5:9; } ++c; } 其他的 elem=jQuery(“”).css({float:'left'}) .text(options.format.charAt(i-1)); 其中。附加(“”); 其中。追加(elem); 其中。附加(“”); } elem=jQuery(“”).css({float:'left'}) .文本('s'); 其中。附加(“”); 其中。追加(elem); 其中。附加(“”); }; //设置或获取元素边距 var保证金=功能(要素,val) { 如果(val!==未定义) 返回数字[elem].css({'marginTop':val+'px'}); 返回parseInt(数字[elem].css('marginTop')。替换('px',''); }; //做这个动作。这是通过“数字图像”步骤完成的。 var moveStep=功能(元素) { 数字[elem]。_digitiinitial=-(数字[elem]。_max*options.digithweight*options.digitImages); 返回函数_move(){ mtop=边距(元素)+options.digithweight; if(mtop==options.digithweight){ 边距(元素,数字[元素]。_digitInitial); 如果(elem>0)移动步骤(elem-1)(); 其他的 { 间隔时间; 对于(var i=0;i0)和&(数字[elem]。uu condmax!==未定义)& (数字[elem-1]。_digitiinitial==边距(elem-1))) 边距(elem,-(数字[elem].\uu condmax*options.digithweight*options.digitImages)); 返回; } 保证金(要素、mtop); if(边距(元素)/options.digithweight%options.digitImages!=0) setTimeout(_move,options.stepTime); 如果(mtop==0)位[elem]。\uu ismax=true; } }; extend(options,userOptions); css({height:options.digithweight,overflow:'hidden'}); createDigits(sct_div_id); 间隔=设置间隔(移动步长(位数.length-1),1000); } 函数timeleft(eventTime){ var now=新日期(); var now_utc=新日期(now.getUTCFullYear()、now.getUTCMonth()、now.getUTCDate()、now.getUTCHours()、now.getUTCMinutes()、now.getUTCSeconds()); var event_time=新日期(eventTime); var t1=now_utc.getTime(); //从日期中删除一小时-60分钟*60秒*1000毫秒--60*60*1000 var t2=event_time.getTime(); var time_left=新日期(parseInt(t2-t1)); if(time_left,javascript,Javascript,Javascript从运行它的机器获取日期。 检查 您需要将时间存储在数据库unix时间戳中,并通过java脚本日期函数根据客户端时区将其转换为客户端时间戳。 受javascript支持我可以设置特定的国家/地区日期时间。代码中只设置UTC时间。我想设置UTC+6日期时间?可能bro?W3学校不是一个很好的参考。例如,他们没有提到。 function timeleft(eventTime) { var now = new Date(); var now_utc = new Da

Javascript从运行它的机器获取日期。 检查


您需要将时间存储在数据库unix时间戳中,并通过java脚本日期函数根据客户端时区将其转换为客户端时间戳。
受javascript支持

我可以设置特定的国家/地区日期时间。代码中只设置UTC时间。我想设置UTC+6日期时间?可能bro?W3学校不是一个很好的参考。例如,他们没有提到。
function timeleft(eventTime) {
    var now = new Date(); 
    var now_utc = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds());
    var event_time = new Date(eventTime);


    var t1 = now_utc.getTime();
    //removes one hour from the date - 60 minutes * 60 seconds * 1000 miliseconds - -60*60*1000
    var t2 = event_time.getTime();
    var time_left = new Date(parseInt(t2-t1));
    if(time_left<0) {
        return "00:00:00:00";
    }
    msPerDay = 24 * 60 * 60 * 1000;
    days = Math.floor(time_left/msPerDay);
    if (days < 10) { days = "0"+days; }
    hours = time_left.getUTCHours();
    if (hours < 10) { hours = "0"+hours;}
    minutes = time_left.getUTCMinutes();
    if (minutes < 10) { minutes = "0"+minutes; }
    seconds = time_left.getUTCSeconds();
    if (seconds < 10) { seconds = "0"+seconds; }

    return(days+":"+hours+":"+minutes+":"+seconds);
}
/*
 * jquery-counter plugin
 *
 * Dual licensed under the MIT and GPL licenses.
 *
 * http://docs.jquery.com/License
 */

jQuery(function(){
    jQuery('.simple_countdown_timer').each(function() {     
        countdown(jQuery('#'+jQuery(this).attr('id')+' .sct_count'),{
            eventTime: jQuery('#'+jQuery(this).attr('id')+' .sct_event_time').text(),
            image: jQuery('#'+jQuery(this).attr('id')+' .sct_image').text(),
        });
    });
});

function countdown(sct_div_id,userOptions)
{
  // Default options
  var options = {
    stepTime: 60,
    // startTime and format MUST follow the same format.
    // also you cannot specify a format unordered (e.g. hh:ss:mm is wrong)
    format: "dd:hh:mm:ss",
    eventTime: "Jan, 1, 2013, 00:00",
    digitImages: 6,
    digitWidth: 13,
    digitHeight: 19,
    timerEnd: function(){},
    image: "http://cdn.live-nhl.com/media-resources/other/countdown-timer/digits-13-19.png"
  };
  var digits = [], interval;

  userOptions.startTime = timeleft(userOptions.eventTime);

  // Draw digits in given container
  var createDigits = function(where) 
  {
    var c = 0;
    var tempStartTime = options.startTime;
    // Iterate each startTime digit, if it is not a digit
    // we'll asume that it's a separator
    for (var i = 0; i < options.startTime.length; i++)
    {
      if (parseInt(tempStartTime.charAt(i)) >= 0) 
      {
        elem = jQuery('<div id="cnt_' + i + '" class="cntDigit" />').css({
          height: options.digitHeight * options.digitImages * 10, 
          float: 'left', background: 'url(\'' + options.image + '\')',
          width: options.digitWidth});
        digits.push(elem);
        margin(c, -((parseInt(tempStartTime.charAt(i)) * options.digitHeight *
                              options.digitImages)));
        digits[c].__max = 9;
        // Add max digits, for example, first digit of minutes (mm) has 
        // a max of 5. Conditional max is used when the left digit has reach
        // the max. For example second "hours" digit has a conditional max of 3         

        switch (options.format.charAt(i)) {
          case 'h':
            digits[c].__max = (c % 2 == 0) ? 2: 9;
            if (c % 2 != 0)
              digits[c].__condmax = 3;
            break;
          case 'd': 
            digits[c].__max = 9;
            break;
          case 'm':
          case 's':
            digits[c].__max = (c % 2 == 0) ? 5: 9;
        }
        ++c;
      }
      else 
        elem = jQuery('<div class="cntDescSeparator"/>').css({float: 'left'})
                .text(options.format.charAt(i-1));

            where.append('<div>');
            where.append(elem);
            where.append('</div>');
    }
        elem = jQuery('<div class="cntDescSeparator"/>').css({float: 'left'})
                .text('s');

            where.append('<div>');
            where.append(elem);
            where.append('</div>');
  };

  // Set or get element margin
  var margin = function(elem, val) 
  {
    if (val !== undefined)
      return digits[elem].css({'marginTop': val + 'px'});

    return parseInt(digits[elem].css('marginTop').replace('px', ''));
  };

  // Makes the movement. This is done by "digitImages" steps.
  var moveStep = function(elem) 
  {
    digits[elem]._digitInitial = -(digits[elem].__max * options.digitHeight * options.digitImages);
    return function _move() {
      mtop = margin(elem) + options.digitHeight;
      if (mtop == options.digitHeight) {
        margin(elem, digits[elem]._digitInitial);
        if (elem > 0) moveStep(elem - 1)();
        else 
        {
          clearInterval(interval);
          for (var i=0; i < digits.length; i++) margin(i, 0);
          options.timerEnd();
          var match_link = digits[elem].parent().parent().parent().children('.match-link').attr('href');
          digits[elem].parent().parent().html('<a href="'+match_link+'" class="live-now"><img width="145" height="35" src="http://cdn.live-nhl.com/media-resources/other/WatchNow.png" class="attachment-medium" alt="WatchNow" title="WatchNow"></a>');

          return;
        }
        if ((elem > 0) && (digits[elem].__condmax !== undefined) && 
            (digits[elem - 1]._digitInitial == margin(elem - 1)))
          margin(elem, -(digits[elem].__condmax * options.digitHeight * options.digitImages));
        return;
      }

      margin(elem, mtop);
      if (margin(elem) / options.digitHeight % options.digitImages != 0)
        setTimeout(_move, options.stepTime);

      if (mtop == 0) digits[elem].__ismax = true;
    }
  };

  jQuery.extend(options, userOptions);
  sct_div_id.css({height: options.digitHeight, overflow: 'hidden'});
  createDigits(sct_div_id);
  interval = setInterval(moveStep(digits.length - 1), 1000);
}

function timeleft(eventTime) {
    var now = new Date(); 
    var now_utc = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds());
    var event_time = new Date(eventTime);


    var t1 = now_utc.getTime();
    //removes one hour from the date - 60 minutes * 60 seconds * 1000 miliseconds - -60*60*1000
    var t2 = event_time.getTime();
    var time_left = new Date(parseInt(t2-t1));
    if(time_left<0) {
        return "00:00:00:00";
    }
    msPerDay = 24 * 60 * 60 * 1000;
    days = Math.floor(time_left/msPerDay);
    if (days < 10) { days = "0"+days; }
    hours = time_left.getUTCHours();
    if (hours < 10) { hours = "0"+hours;}
    minutes = time_left.getUTCMinutes();
    if (minutes < 10) { minutes = "0"+minutes; }
    seconds = time_left.getUTCSeconds();
    if (seconds < 10) { seconds = "0"+seconds; }

    return(days+":"+hours+":"+minutes+":"+seconds);
}
var now = new Date();