【问题标题】:Flex Builder dateFormatter timezone offsetFlex Builder dateFormatter 时区偏移
【发布时间】:2012-01-31 23:15:11
【问题描述】:

我有一个获取 RSS 源的 Flex Mobile 应用程序,但时区不正确。我希望它在 CST 中部时间。需要格式化时区。我在下面粘贴了工作代码,但需要修复时区问题。

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:ns1="*"
        backgroundColor="#74171E" title="Mediacom 2 / Paulbunyan 32"
        viewActivate="refresh()">

    <fx:Script>
        <![CDATA[
            protected function getData():void
            {
                getDataResult.token = iCTVChannel232.getData();
            }
            public function refresh(): void {
                getData();
            }
            private function dateFormat(item:Object,column:GridColumn):String
            {
                return pubDateFormatter.format(item.pubDate);
            }
        ]]>
    </fx:Script>

    <fx:Declarations>
        <s:DateTimeFormatter id="pubDateFormatter" useUTC="false" dateTimePattern="MM-dd K:mm a"/>
        <s:CallResponder id="getDataResult"/>
        <ns1:ICTVChannel232 id="iCTVChannel232"/> 
    </fx:Declarations>
    <s:DataGrid id="dataGrid" left="10" right="10" top="10" bottom="10">
        <s:columns>
            <s:ArrayList>
                <s:GridColumn dataField="pubDate" width="80" headerText="Date" labelFunction="dateFormat"></s:GridColumn>
                <s:GridColumn dataField="title" headerText="title"></s:GridColumn>
            </s:ArrayList>
        </s:columns>
        <s:AsyncListView list="{getDataResult.lastResult}"/>

    </s:DataGrid>
    <s:actionContent>
        <s:Button icon="@Embed('/assets/refreshico.png')"
                  click="Object(navigator.activeView).refresh()"/>
    </s:actionContent>

【问题讨论】:

    标签: android timezone flash-builder flexbuilder


    【解决方案1】:

    Flash 中的 Date 对象始终设置为计算机的时间设置。如果计算机已经在 CDT 时区,那么从对象中获取任何属性都会很好。但是,如果您想将时区“转换”为计算机未设置的时区,您可以获取 UTC 时间并像这样为 CDT 偏移它:

    var date:Date = new Date();
    var timezone:int = -5;
    date.hours = date.hoursUTC + timezone;
    

    但是,您正在尝试获取实际的 CDT 时间,该时间仅在某些地区的夏季有效。为此,Flash 不可能准确地知道那是什么时候,除非您对异常进行编码(即,如果在此日期和该日期之间,则执行 -6,否则执行 -5)并且您还需要知道用户的实际位置(除非用户向您提供该信息,否则通过 Flash 是不可能的)。

    <fx:Script>
            <![CDATA[
                protected function getData():void
                {
                    getDataResult.token = iCTVChannel232.getData();
                }
                public function refresh(): void {
                    getData();
                }
                private function dateFormat(item:Object,column:GridColumn):String
                {
                    var date:Date = item.pubDate;
                    var timezone:int = -5;
                    date.hours = date.hoursUTC + timezone;
                    return pubDateFormatter.format(date);
                }
            ]]>
        </fx:Script>
    

    【讨论】:

    • 该应用是针对小区域的。我们是明尼苏达州的公共电视台,该应用程序适用于我们的收视区。
    • 我是 flex 新手,您能帮我放置上面示例中的代码吗?我试图放置
    • 运行编辑后的代码后,它会返回以下错误。我非常感谢您帮助我解决这个问题。
    • TypeError:错误 #1034:类型强制失败:无法将“Thu,2012 年 2 月 2 日 15:00:00 GMT”转换为日期。在视图::Channel2Schedule/dateFormat()
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-31
    • 1970-01-01
    • 2011-09-02
    • 2017-11-07
    • 1970-01-01
    相关资源
    最近更新 更多