将忽略时区偏移的日期字符串

时间:2016-07-26 12:17:45

标签: javascript date

我在东部时间(美国和加拿大)的(UTS-05:00)

.login-body { background-color: #f1f2f7 } .form-signin { max-width: 330px; //margin: 50px auto 50px; background: #fff; border-radius: 3px; -moz-border-radius: 3px; -webkit-border-radius: 3px; } .form-wrapper { //padding-bottom: 70px } .login-bg { margin-top: -40px; margin-bottom: -50px; //background-color: #f1f2f7; } 秒。

现在,我有一个API端点(JSON),它返回一个这样的日期字符串。

 <!-- Sequence Modern Slider -->
    <div id="da-slider" class="da-slider">

            <div class="da-slide">
            <div class="container">
              <div class="row">
                <div class="col-md-12">
              <h2>
                <i>BUSINESS TOOLS</i>
                <br>
                <i>FOR YOUR</i>
                <br>
                <i>SUCCESS</i>
              </h2>
              <p>
                <i>Data visualized</i>
                <br />
                <i>to meet your needs!</i>
              </p>
              <a href="#" class="btn btn-info btn-lg da-link">
                Read more
              </a>
              <div class="da-img">
                <img src="img/parallax-slider/images/graph.jpg" alt="" />
              </div>
            </div>
          </div>
        </div>
      </div>


            <div class="da-slide">
            <div class="container">
        <div class="row">
          <div class="col-md-12">
        <h2>
          <i>RESPONSIVE VIDEO</i>
            <br />
          <i>SUPPORT AND</i>
            <br />
          <i>MANY MORE</i>
        </h2>
        <p>
          <i>Lorem ipsum dolor amet</i>
            <br />
          <i>tempor incididunt ut</i>
        </p>
        <a href="#" class="btn btn-info btn-lg da-link">
          Read more
        </a>
        <div class="da-img">
          <img src="img/parallax-slider/images/3.png" alt="image01" />
        </div>
      </div>
          </div>
        </div>
      </div>


      <div class="da-slide">
      <div class="container">
        <div class="row">
          <div class="col-md-12">
        <h2>
          <i>USING BEST WEB</i>
            </br>
          <i>SOLUTIONS WITH</i>
            </br>
          <i>HTML5/CSS3</i>
        </h2>
        <p>
          <i>Lorem ipsum dolor amet</i>
          <br />
          <i>tempor incididunt ut</i>
          <br />
          <i>veniam omnis </i>
        </p>
        <a href="#" class="btn btn-info btn-lg da-link">
          Read more
        </a>
        <div class="da-img">
          <img src="img/parallax-slider/images/1.png" alt="image01" />
        </div>
      </div>
      </div>
      </div>
      </div>

      <!--<nav class="da-arrows">
        <span class="da-arrows-prev">
        </span>
        <span class="da-arrows-next">
        </span>
      </nav>-->
    </div>

    <!-- Login start -->
    <div class="login-bg">
        <div class="container">
            <div class="form-wrapper">
            <form class="form-signin wow fadeInUp" action="index.html">
            <h2 class="form-signin-heading">sign in now</h2>
            <div class="login-wrap">
                <input type="text" class="form-control" placeholder="User ID" autofocus>
                <input type="password" class="form-control" placeholder="Password">
                <label class="checkbox">
                    <input type="checkbox" value="remember-me"> Remember me
                    <span class="pull-right">
                        <a data-toggle="modal" href="#myModal"> Forgot Password?</a>

                    </span>
                </label>
                <button class="btn btn-lg btn-login btn-block" type="submit">Sign in</button>
                <p>or you can sign in via social network</p>
                <div class="login-social-link">
                    <a href="index.html" class="facebook">
                        <i class="fa fa-facebook"></i>
                        Facebook
                    </a>
                    <a href="index.html" class="twitter">
                        <i class="fa fa-twitter"></i>
                        Twitter
                    </a>
                </div>
                <div class="registration">
                    Don't have an account yet?
                    <a class="" href="registration.html">
                        Create an account
                    </a>
                </div>

            </div>

              <!-- Modal -->
              <div aria-hidden="true" aria-labelledby="myModal" role="dialog" tabindex="-1" id="myModal" class="modal fade">
                  <div class="modal-dialog">
                      <div class="modal-content">
                          <div class="modal-header">
                              <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                              <h4 class="modal-title">Forgot Password ?</h4>
                          </div>
                          <div class="modal-body">
                              <p>Enter your e-mail address below to reset your password.</p>
                              <input type="text" name="email" placeholder="Email" autocomplete="off" class="form-control placeholder-no-fix">

                          </div>
                          <div class="modal-footer">
                              <button data-dismiss="modal" class="btn btn-default" type="button">Cancel</button>
                              <button class="btn btn-success" type="button">Submit</button>
                          </div>
                      </div>
                  </div>
              </div>
              <!-- modal -->

          </form>
          </div>
        </div>
    </div>
    <!-- Login end -->

在这里,我将它传递给Date构造函数,就像这样

&#13;
&#13;
new Date().getTimezoneOffset() == 300
&#13;
&#13;
&#13;

Mozilla Firefox控制台显示

  

日期{Fri Jan 01 2016 00:40:00 GMT-0500(东部夏季时间)}

Google Chrome控制台显示

  

2015年12月31日星期四19:40:00 GMT-0500(东部标准时间)

Chrome正在考虑使用TimezoneOffset而Firefox则不然。我该怎样做才能获得一个不会像Chrome中的FireFox一样考虑抵消的日期?

2 个答案:

答案 0 :(得分:3)

您可以通过以下方式完成:

use GuzzleHttp\Client as LinkedinClient;
use PHPHtmlParser\Dom as Parser;

public function authLinkedin()
{
    $client = new LinkedinClient(['base_url' => 'https://www.linkedin.com']);

    try {
        $postData = [
            'session_key'       => 'My_email',
            'session_password'  => 'My_password',
            'action' => 'login'
            ];

        $request = $client->createRequest('POST', '/uas/login', ['body' => $postData, 'cookies' => true]);

        $response = $client->send($request);

        if ($response->getStatusCode() === 200) {
            $parser = new Parser();
            $parser->load($client->get('https://www.linkedin.com/', ['cookies' => true])->getBody());

            return $parser;
        } else {
            Log::store("Authorization error", Log::TYPE_ERROR, $request->getStatusCode());
            return null;
        }
        return $request;
    } catch (Exception $ex) {
        Log::store("Failure get followers", Log::TYPE_ERROR, $ex->getMessage());

        return null;
    }
}

答案 1 :(得分:0)

这个黑客工作(不是很干净,但做的工作)

var dateString = '2016-07-27T01:40:30';
var dateParts = dateString.split(/-|T|:/);
var saneDate = new Date(
    +dateParts[0], 
    dateParts[1] - 1, 
    +dateParts[2], 
    +dateParts[3], 
    +dateParts[4], 
    +dateParts[5]);
console.log(saneDate);