Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 具有特定语法的json日期格式_Jquery_Html_Json - Fatal编程技术网

Jquery 具有特定语法的json日期格式

Jquery 具有特定语法的json日期格式,jquery,html,json,Jquery,Html,Json,我知道这个问题有几个高质量的答案,但我正在努力解决语法问题,以使其能够正常工作: $.getJSON( "ticketweb.json", function(data){ $.each(data.events, function(){ $('ul#listings').append("<li><div class=event-col><span class=name>" +this

我知道这个问题有几个高质量的答案,但我正在努力解决语法问题,以使其能够正常工作:

$.getJSON( "ticketweb.json",
            function(data){
              $.each(data.events, function(){
              $('ul#listings').append("<li><div class=event-col><span class=name>" +this.eventname+ "</span><p>" +this.eventurl+ "</p><div class=date>" +this.dates.startdate+ "</div><p>" +this.eventimages+ "</p><p>" +this.venue.name+ "</p></div></li>");

            });
        });

如果我理解正确,您有两个选择-更改服务器发送的日期格式,或者在客户端收到日期后设置日期格式

如何实现后者的示例:

var dateStr = this.dates.startdate // 20120629100000
var formattedDate = dateStr.substr( 6, 2) + '/'
                  + dateStr.substr( 4, 2) + '/'
                  + dateStr.substr( 0, 4) + ' ' 
                  + dateStr.substr( 8, 2) + ':'
                  + dateStr.substr(10, 2) + ':'
                  + dateStr.substr(12, 2);

... '<div class="date">' + formattedDate + '</div>' ...
var dateStr=this.dates.startdate//20120629100000
var formattedDate=dateStr.substr(6,2)+'/'
+dateStr.substr(4,2)+'/'
+dateStr.substr(0,4)+”
+dateStr.substr(8,2)+':'
+dateStr.substr(10,2)+':'
+dateStr.substr(12,2);
... '' + formattedDate+“”。。。

此特定示例将输出:
29/06/2012 10:00:00(DD/MM/YYYY HH:MM:SS)

显示一些值的实际json示例以及所需日期的格式
 "events":   [
    {
  "eventid": "4419605",
  "facebookeventid": "",
  "eventname": "",
  "description": "",
  "eventurl": "",
  "additionallistingtext": "",
  "status": "SalesEnded",
  "tags": "",
  "spotifyuri": "",
  "dates":       {
    "startdate": "20120529010000",
    "enddate": "20121231235500",
    "onsaledate": "20120309084000",
    "announcedate": "20120309115333",
    "timezone": "EDT"
  },
  "venue":       {
    "venueid": "210795",
    "name": "Online",
    "venueurl": "",
    "city": "Online",
    "state": "",
    "postalcode": "00000",
    "country": "US",
    "address": "Online",
    "twitterid": "",
    "venueimages":         {
      "large": "",
      "small": ""
    }
  },
  "eventimages": [""],
  "prices":       {
    "pricelow": "$195.00",
    "pricehigh": "$195.00",
    "pricedisplay": "$195.00"
  },
  "attractionList":       [
            {
      "sequence": "0",

      "billing": "1.00",
      "genre": "Seminar/Lecture",
      "links": "",
      "media": ""
    },
            {
      "sequence": "1",
      "billing": "0.75",
      "links": "",
      "media": ""
    },
            {
      "sequence": "2",
      "billing": "0.75",
      "links": "",
      "media": ""
    }
  ]
},
var dateStr = this.dates.startdate // 20120629100000
var formattedDate = dateStr.substr( 6, 2) + '/'
                  + dateStr.substr( 4, 2) + '/'
                  + dateStr.substr( 0, 4) + ' ' 
                  + dateStr.substr( 8, 2) + ':'
                  + dateStr.substr(10, 2) + ':'
                  + dateStr.substr(12, 2);

... '<div class="date">' + formattedDate + '</div>' ...