计算时间的ActionScript 3之间留有分钟 [英] calculate minutes left between hours actionscript 3

查看:251
本文介绍了计算时间的ActionScript 3之间留有分钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用AS3拉XML数据中,一个场是在XML时间字段,并显示一小时。我收到的日期,然后在AS3加载基于格兰一次在XML设置适当的节点。这是所有工作完美 - 我有两次作为变量,一个是系统时​​间(这是在UTC时间设置),另一种是提前一小时。

I'm using AS3 to pull XML data, one field is a time field in the XML and displays an hour. I'm getting the date and then the AS3 loads the proper node based on teh time set in the XML. This is all working perfect - I have two times as variables, one is the system time (which is set in UTC time) the other is one hour ahead.

这两个变量是currentHour的和newHour - 它做我想要的一切,但是我想现在创建这两个小时,并显示剩余时间的分钟之间倒计时

The two variables are currentHour and newHour - it's doing everything I want however I'd like to now create a countdown between these two hours and display time remaining in the minutes.

下面是完整的code为。 利用XML获取时间AS3

Here is the complete code for that. Get the time from XML using AS3

这些看起来简单的,但我有一个困难时期。我试过这样的:

These seems straight forward but I'm having a hard time. I've tried this:

var data:Array = [currentHour, newHour];

var aDate:String = data[0].split(" ")[0];

var dateElements:Array = aDate.split("-");
var date1:Date = new Date();
date1.setMinutes(int(data[0].split(" ")[1].split(":")[0]));
dateElements = data[1].split(" ")[0].split("-");
var date2:Date = new Date();
date2.setMinutes(int(data[1].split(" ")[1]));
var elapse:Number = date2.getTime() - date1.getTime();
trace("minutes: " + date2.getMinutes());

但是,这是不对的,所以我尝试这样的:

But that isn't right, so I tried this:

if(currentHour < newHour)
{
var dayDiff:Number = newHour-currentHour;
// make sure it’s in the future
if (dayDiff > 0)
{
var seconds:Number = dayDiff / 1000;
var minutes:Number = seconds / 60;
}
trace(minutes, seconds);
}

如果有人可以帮助我摆脱这种困境,这将是惊人的。谢谢!

If someone could help me get unstuck that would be amazing. Thank you!

推荐答案

创建一个新的答案,并没有包含previous之一,我试图找出实际的问题是垃圾邮件,什么的期望该方案是。反正总结:

Created a new answer which didn't contain the spam from previous one where I tried to figure out what the actual issue was and what the expectations of the program was. Anyways to summarize:

用户想,给出了具体的日期/时间,找出了多久,直到下一个完整小时,所以例如由于时间下午4时47分想弄清楚多少分,秒留到下午5点。

User wanted to, given a specific date/time, find out how long until the next complete hour, so for instance given the time 4:47pm wanted to find out how many minutes and seconds left until 5:00pm.

import flash.display.MovieClip;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.globalization.NumberFormatter;
import flash.utils.getTimer;
import flash.utils.Timer;

var timer:Timer = new Timer(250);
var my_date:Date = new Date();
var targetDate:Date = new Date();

//calculate how many total milliseconds left until next whole hour since that is how as3 is using Date-objects
var timeUntilWholeHourMS:Number = (60 - my_date.getMinutes()) * 60 * 1000;
targetDate.setTime(my_date.getTime() + timeUntilWholeHourMS);
//clear the "second and milliseconds" part of the new time since we want the whole hours
targetDate.setSeconds(0, 0);

var secondsLeft:Number = (targetDate.time - new Date().time) / 1000;
//make sure it is in the future
if (secondsLeft > 0) {
    timer.addEventListener(TimerEvent.TIMER, onTimer);
    timer.start();
}

function onTimer(e:flash.events.TimerEvent):void {
    secondsLeft = (targetDate.time - new Date().time)/1000;

    if (secondsLeft > 0) {
        var minutes:Number = Math.floor(secondsLeft/60);
        var seconds:Number = Math.floor(secondsLeft%60);
        trace("minutes left: " + minutes, ", seconds left: " + seconds);
    } else {
        //time limit reached
        timer.removeEventListener(TimerEvent.TIMER, onTimer);
        timer.stop();
        trace("Time limit reached!");
    }
}

这篇关于计算时间的ActionScript 3之间留有分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆