Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.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
Javascript 如何格式化fb.created\u时间_Javascript_Facebook_Format - Fatal编程技术网

Javascript 如何格式化fb.created\u时间

Javascript 如何格式化fb.created\u时间,javascript,facebook,format,Javascript,Facebook,Format,我是javascript新手,我使用了这里的教程:但是我在格式化facebook提供的日期时遇到了问题。我的网站是,我的代码如下: (function($){ $.fn.fbstatus = function(options) { set = jQuery.extend({ username: 'Removed for privacy', token: 'Removed for privacy',

我是javascript新手,我使用了这里的教程:但是我在格式化facebook提供的日期时遇到了问题。我的网站是,我的代码如下:

(function($){

    $.fn.fbstatus = function(options) {

        set = jQuery.extend({
            username: 'Removed for privacy',
            token: 'Removed for privacy',
            loading_text: null
        }, options);

        function fbstatus_link(text){
            return text.replace(/(href="|<a.*?>)?[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/g, function($0, $1) {
              return $1 ? $0 : $0.link($0);
            });
        }


        //Set Url of JSON data from the facebook graph api. make sure callback is set with a '?' to overcome the cross domain problems with JSON
        var url = "Removed for privacy";

        $(this).each(function(i, widget){
            var loading = $('<p class="loading">'+set.loading_text+'</p>');
            var theObject = $(this);
                if (set.loading_text) $(widget).append(loading);


            //Use jQuery getJSON method to fetch the data from the url and then create our unordered list with the relevant data.
            $.getJSON(url,function(json){
                var html = "<ul>";

                    //loop through and within data array's retrieve the message variable.
                    $.each(json.data,function(i,fb){

                        if (fb.message) {
                            html += "<li>" + fbstatus_link(fb.message) + "<br>" + fb.created_time + "</li>" + "<br>";
                        }

                    });
                html += "</ul>";


                //A little animation once fetched
                theObject.animate({opacity:0}, 500, function(){

                        theObject.html(html);

                });

                theObject.animate({opacity:1}, 500);

            });

        });

    };

})(jQuery);
(函数($){
$.fn.fbstatus=功能(选项){
set=jQuery.extend({
用户名:“为了隐私而删除”,
令牌:“出于隐私而删除”,
正在加载文本:null
},选项);
功能FBU状态链接(文本){
返回文本。替换(/(href=“|”)?[A-Za-z]+:\/\/\/[A-Za-z0-9-\]+\.[A-Za-z0-9-\:%&\?\/.=]+/g,函数($0,$1){
返回$1?$0:$0.link($0);
});
}
//设置facebook graph api中JSON数据的Url。确保回调设置为“?”,以克服JSON的跨域问题
var url=“为隐私而删除”;
$(此).each(函数(i,小部件){
var loading=$('

'+set.loading_text+'

'); var theObject=$(此项); if(set.loading_text)$(小部件).append(加载); //使用jQuery getJSON方法从url获取数据,然后使用相关数据创建无序列表。 $.getJSON(url,函数(json){ var html=“
    ”; //在数据数组中循环并检索消息变量。 $.each(json.data,函数(i,fb){ 如果(fb.信息){ html+=“
  • ”+fbstatus\u link(fb.message)+“
    ”+fb.created\u time+”
  • “+”
    ”; } }); html+=“
”; //一个小动画一旦被抓取 动画({opacity:0},500,function()){ html(html); }); 动画对象({opacity:1},500); }); }); }; })(jQuery);
任何帮助都将不胜感激。

根据“日期”下的主要内容,您可以要求API以您想要的任何日期格式返回结果-为什么不让Facebook以您喜欢的格式返回日期呢

摘自文件:

所有日期字段都以ISO-8601格式的字符串返回。您可以选择通过指定“日期格式”覆盖日期格式 查询参数。接受的格式字符串与 被php日期函数接受。例如, 返回 平台页面的提要,带有unixtime格式的日期


您可以使用javascript函数

string.substring(from, to);
这将允许您将起始字符(0表示字符串的起始)指定为所需的最后一个字符(长度-5)


这里有一个简单的方法来做到这一点

//graph API call
https://graph.facebook.com/YOURNAME?fields=YOURFIELDSHERE&date_format=F j, Y, g:i a&access_token=ACCESSTOKENHERE"

结果将是帖子的日期,如:2017年4月13日下午4:40,我发现这很有用。我只是删掉了日期之后的所有内容。我只希望在1位数的日子里,它不会从日期中删除一位数。我减去了11位数。我不知道如何将其集成到我现有的代码中。我是javascript.add的超级高手date_format=X到您的API调用,其中X表示您期望的日期格式-您可以在此处看到可能的选项:-它使用与图形APIC相同的占位符值。请复制我的API调用并插入代码。我不确定将其放置在何处,因为我不确定API调用是什么…对不起,伙计。
//graph API call
https://graph.facebook.com/YOURNAME?fields=YOURFIELDSHERE&date_format=F j, Y, g:i a&access_token=ACCESSTOKENHERE"