Twitter<创建于>将值转换为 Flash 中友好的时间格式

发布于 2024-12-02 18:33:07 字数 1595 浏览 0 评论 0原文

我已经用谷歌搜索了几个小时,但还没有找到这个问题的解决方案。

目前,我从 Twitter xml 文件中检索数据: http://twitter.com/statuses /user_timeline.xml?screen_name=clubbluecanopy

一切正常,我的日期格式显示:Fri Aug 12 03:25:40 +0000 2011年 但我希望它显示这一点: 17 天前

,这是我的 flash as3 代码:

var myXMLLoader:URLLoader = new URLLoader();
//myXMLLoader.load(new URLRequest("http://twitter.com/statuses/user_timeline.xml?screen_name=arunshourie"));

myXMLLoader.load(new URLRequest("twitter.php"));
myXMLLoader.addEventListener(Event.COMPLETE, processXML);

function processXML(e:Event):void{
var myXML:XML = new XML(e.target.data);
trace(myXML.status[0].text);

tweet_1.text = String(myXML.status[0].text);
time.text= String(myXML.status[0].created_at);



}

这是 php 代码:

<?php
/*
* @return string
* @param string $url
* @desc Return string content from a remote file
* @author Luiz Miguel Axcar ([email protected])
*/

function get_content($url)
{
$ch = curl_init();

curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0);

ob_start();

curl_exec ($ch);
curl_close ($ch);
$string = ob_get_contents();

ob_end_clean();

return $string;
}

#usage:
$content = get_content ("http://twitter.com/statuses/user_timeline.xml?screen_name=clubbluecanopy");
echo $content;
?>

我也使用了 crossdomain.xml

,如果有人可以帮助我,我将不胜感激!谢谢! :)

I have been googling for hours and have not yet found a solution to this problem.

currently, I retrive the data from the twitter xml file: http://twitter.com/statuses/user_timeline.xml?screen_name=clubbluecanopy

everything works fine, my date format shows this: Fri Aug 12 03:25:40 +0000 2011
But I want it to show this: 17 days ago

here's my flash as3 code:

var myXMLLoader:URLLoader = new URLLoader();
//myXMLLoader.load(new URLRequest("http://twitter.com/statuses/user_timeline.xml?screen_name=arunshourie"));

myXMLLoader.load(new URLRequest("twitter.php"));
myXMLLoader.addEventListener(Event.COMPLETE, processXML);

function processXML(e:Event):void{
var myXML:XML = new XML(e.target.data);
trace(myXML.status[0].text);

tweet_1.text = String(myXML.status[0].text);
time.text= String(myXML.status[0].created_at);



}

Here's the php code:

<?php
/*
* @return string
* @param string $url
* @desc Return string content from a remote file
* @author Luiz Miguel Axcar ([email protected])
*/

function get_content($url)
{
$ch = curl_init();

curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_HEADER, 0);

ob_start();

curl_exec ($ch);
curl_close ($ch);
$string = ob_get_contents();

ob_end_clean();

return $string;
}

#usage:
$content = get_content ("http://twitter.com/statuses/user_timeline.xml?screen_name=clubbluecanopy");
echo $content;
?>

I have used crossdomain.xml as well

would appreciate if someone can help me! thanks! :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

演多会厌 2024-12-09 18:33:07

Fri Aug 12 03:25:40 +0000 2011 表示星期五,2011 年 8 月 12 日,03 小时 25 分 40 秒 GMT

是 Flash 的本机日期格式字符串

您可以创建另一个函数,它将为您提供所需的输出:

    private function toRelativeDate(d:Date):String {
            var now:Date=new Date();
            var millisecs:int=now.valueOf()-d.valueOf(); //gives you the num. of milliseconds between d and now
            var secs:int=int(millisecs / 1000);
            if(secs < 60) {
                return secs + " seconds ago";
            }else if(secs < 60*60) {
                return Math.round(secs / 60) + " minutes ago";
            } else if(secs < 60*60*24) {
                return Math.round(secs / (60*60)) + " hours ago";
            } else {
                return Math.round(secs / (60*60*24)) + " days ago";
            }
        }

这 可以按如下方式使用它:

time.text= toRelativedate(myXML.status[0].created_at);

Fri Aug 12 03:25:40 +0000 2011 means Friday, 12th August 2011, 03hrs 25min 40sec GMT

This is Flash's native date formatted string

You can create another function which will give you the required output:

    private function toRelativeDate(d:Date):String {
            var now:Date=new Date();
            var millisecs:int=now.valueOf()-d.valueOf(); //gives you the num. of milliseconds between d and now
            var secs:int=int(millisecs / 1000);
            if(secs < 60) {
                return secs + " seconds ago";
            }else if(secs < 60*60) {
                return Math.round(secs / 60) + " minutes ago";
            } else if(secs < 60*60*24) {
                return Math.round(secs / (60*60)) + " hours ago";
            } else {
                return Math.round(secs / (60*60*24)) + " days ago";
            }
        }

You could use it as follows:

time.text= toRelativedate(myXML.status[0].created_at);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文