Flex 4 utc日期时间格式问题

发布于 2024-11-15 22:05:40 字数 1619 浏览 3 评论 0原文

这是我的函数,当时间偏移为整数(1,2,3,4...)时,它们工作正常,但当时间偏移为 3.5(3:30)、4.5(4:30)时,它们不起作用。 有人可以帮我解决这个问题吗:

private function init_vars():void
            {
timeZoneOffset = FlexGlobals.topLevelApplication.parameters.clock_time_zone; // I load this with js
                timeZoneOffset = 5,50; // just for test
            }

            private function tick(event:TimerEvent):void 
            {                   
                var local: Date = new Date();

                var utc: Date = new Date(local.getTime() + (local.getTimezoneOffset() * 60000));

                var utcTime:Number=utc.getTime();




                var new_offset_date:Number = utcTime + ((3600000) * timeZoneOffset);
                var new_date:Date = new Date(new_offset_date);              
                currentTime = new Date(new_date);
                showTime(currentTime); // another function just to display time                                 
            } 


private function showTime(time:Date):void
            {
                seconds = time.getSeconds();
                minutes= time.getMinutes();
                hours= time.getHours();

                            //rotate
                this.secondsPointer.rotation = (seconds * 6) - 90;
                this.minutesPointer.rotation = (minutes * 6) - 90;              
                this.hoursPointer.rotation = (hours * 30) + (minutes * 0.5) - 90;
                this.secondsPointer.visible = true;
                this.minutesPointer.visible = true;
                this.hoursPointer.visible = true;                           
            }

here are my functions they work fine when timeoffset is round number(1,2,3,4...),but when is 3.5(3:30), 4.5(4:30) it doesnt work.
Can someone help me with this :

private function init_vars():void
            {
timeZoneOffset = FlexGlobals.topLevelApplication.parameters.clock_time_zone; // I load this with js
                timeZoneOffset = 5,50; // just for test
            }

            private function tick(event:TimerEvent):void 
            {                   
                var local: Date = new Date();

                var utc: Date = new Date(local.getTime() + (local.getTimezoneOffset() * 60000));

                var utcTime:Number=utc.getTime();




                var new_offset_date:Number = utcTime + ((3600000) * timeZoneOffset);
                var new_date:Date = new Date(new_offset_date);              
                currentTime = new Date(new_date);
                showTime(currentTime); // another function just to display time                                 
            } 


private function showTime(time:Date):void
            {
                seconds = time.getSeconds();
                minutes= time.getMinutes();
                hours= time.getHours();

                            //rotate
                this.secondsPointer.rotation = (seconds * 6) - 90;
                this.minutesPointer.rotation = (minutes * 6) - 90;              
                this.hoursPointer.rotation = (hours * 30) + (minutes * 0.5) - 90;
                this.secondsPointer.visible = true;
                this.minutesPointer.visible = true;
                this.hoursPointer.visible = true;                           
            }

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

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

发布评论

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

评论(1

左耳近心 2024-11-22 22:05:40

我运行了你的代码并且运行良好。我刚刚跟踪了 currentTime 因为我没有您的 showTime 函数,该错误是否可能在该函数中?

如果可以的话,我建议尝试如下操作:

date.setUTCHours(date.getUTCHours() + hoursDifference); //5
date.setUTCMinutes(date.getUTCMinutes + minutesDifference); //30

使用以毫秒为单位的时间修改日期,具体取决于您实际使用应用程序的方式/地点/时间,在夏令时的情况下可能会产生奇怪的错误。而且您不想处理每年仅在世界某些国家/地区发生两次的错误。

I ran your code and it worked fine. I just traced currentTime because I didn't have your showTime function, is it possible that the bug is in that function?

I would recommend to try something like the following if you can:

date.setUTCHours(date.getUTCHours() + hoursDifference); //5
date.setUTCMinutes(date.getUTCMinutes + minutesDifference); //30

Modifying dates using the time in milliseconds, depending on how/where/when you actually use the application might create weird bugs in case of daylight savings. And you don't want to deal with a bug that might happen only twice a year in only certain countries of the world.

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