jquery从getJSON转换时间戳

时间:2017-06-27 16:37:23

标签: jquery json

我正在尝试获取数据json计划航班和航班时刻表的数据json内容时间戳,并尝试转换为当地时间

我的代码:

$(document).ready(function() {
  $.getJSON("v1/airport.json?code=bgw", function(data) {

    $.each(data.result.response.airport.pluginData.schedule.arrivals.data, function() {
      var d = new Date("<p>" + this.flight.time.scheduled.arrival + "</p>" * 1000)


      $("#id").append("<p>" + this.flight.identification.number.default+"</p>");


      if (this.flight.airport.origin) {
        $("#city").append("<p>" + this.flight.airport.origin.position.region.city + "</p>");
      }

    });

  });

});

我尝试使用此代码来获取时间,但它无效

var d = new Date("<p>" + this.flight.time.scheduled.arrival + "</p>" * 1000)

my data json link

1 个答案:

答案 0 :(得分:0)

工作正常:)

 $ (document).ready (function(){
        $.getJSON("/v1/airport.json?code=bgw", function(data){

        $.each(data.result.response.airport.pluginData.schedule.arrivals.data, function(){
    var d = new Date(this.flight.time.scheduled.arrival * 1000)


          $("#id").append("<p>"+this.flight.identification.number.default+"</p>");
          $("#time").append("<p>"+d+"</p>");


          if (this.flight.airport.origin) {
            $("#city").append("<p>"+this.flight.airport.origin.position.region.city+"</p>");
          } 

        });

        });

    });