I'm trying to make a countdown timer, where I could easily set the endDate variable in html...
I can send strings to AS3 with flashvars="endDate=123", but how do I make it to be date (for example christmas)? - I need it to be date because then in AS3 I have something like endDate - todayDate = timeRemaining
Just pass date to flash vars using formats specified here and parse that string in AS3 using Date.parse() method.
In this example you get a countdown in days to Xmas.
var dateFromFlashVar : String = "2013/12/25 15:30:20 GMT+0300";
trace( new Date( new Date( Date.parse( dateFromFlashVar ) ).time - new Date().time ).getDate().toString() );
to transfrom a unix_timestamp date to as3 Date, you can do:
// unixTimeStamp is in seconds so we multiply by 1000 because flash Date take miliseconds
var date:Date = new Date( unixTimeStamp*1000 );
to get back unix timestamp of a date you can do:
// divide by 1000 to get seconds instead of miliseconds
var timeStamp:int = date.time / 1000;
i hope this is what you where searching for
Related
The question is how is it possible to get difference in days from before to today and knowing this difference is happened in the past?
Yes its possible to get difference in days from before to today, all you need is the dates. for the example this is some check in and check out date diff.
// Params in date
public static function getDateDifference($check_in, $check_out)
{
$check_in = strtotime($check_in);
$check_out = strtotime($check_out);
$date_difference = $check_out - $check_in;
$date_difference = round($date_difference / (60 * 60 * 24));
return $date_difference;
}
I use a primefaces extension timer with the following code :
<pe:timer
style="color:darkgrey;"
timeout="1000"
forward="false"
format="HH:mm:ss"/>
But I have a start value. The previous code start from the value 00:00:00, but I have a start time from a Java bean. I have a Date object, or date as long type (from 1970) which is the value from I want to start.
For example I got 1548434800083 or 17:47 25/01/2019 and I want to display the time between this date and now. So how I can set my start value with this date ? I got milliseconds but I can get seconds instead of.
The solution is the following, I have a Java bean, that contain a date in millisecond. I get it with the function getTime() from the Java class Date.
I display my counter, chronometer with the primefaces code :
<pe:timer
style="color:grey;"
forward="true"
formatFunction="return displayElapsedTime('#{synopticBean.longEnteredTime}');"/>
That code call a javascript function, that return a format counter/chronometer :
function displayElapsedTime(longEnteredTime){
var now = new Date();
var elapsedTime = now.getTime() - longEnteredTime;
var numHours = Math.floor(elapsedTime / 3600000);
var minutesAndSecondMS = elapsedTime - numHours;
var minutes = Math.floor((minutesAndSecondMS % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((minutesAndSecondMS % (1000 * 60)) / 1000);
var innerHtmlText = (('0' + (numHours)).slice(-2) + ":" +('0' + (minutes)).slice(-2) + ":" + ('0' + (seconds)).slice(-2));
return innerHtmlText;
}
It display a duration, the number of hours. I only count with hours, no day.
Best solution for your case is formatting. But sometime we need to set start value of primefaces timer:
Run javascript:
PF('timer').currentTimeout = 100;
I am an freelance animator in flash with very limited knowledge in AS3. I make animation videos in swf format and sell it for money. Most of the time, my clients give me a small script and ask for a sample based on the script without any watermark or logo embeded. I have to oblige in order to win the chance of getting the work. Most of the time, the client does not respond after they get the sample and I think that they are getting their work done for free.
I want to embed a script in AS3 in such a way that the video will play for only a pre-defined number of days( eg 3 days ) or till a particular date.
Please help
you have to put your animation in one MovieClip.
I named it 'animation', then set your expire date, I commented where to set
function getDaysBetweenDates(date1:Date, date2:Date) : int {
var oneDay:Number = 1000 * 60 * 60 * 24;
var date1Milliseconds:Number = date1.getTime();
var date2Milliseconds:Number = date2.getTime();
var differenceMilliseconds:Number = date1Milliseconds - date2Milliseconds;
return Math.round(differenceMilliseconds/oneDay);
}
var year : int = 2014; //here you put the year, month and the day when you want to expire
var month : int = 12;
var day : int = 28;
var daysRemaining = getDaysBetweenDates(new Date(year, month-1, day+1), new Date());
timeTXT.text = daysRemaining.toString(); //you can create dinamyc text and show to your client how much time he has befor the animation expire
if(daysRemaining <= 0) {
animation.visible = false; //here we make animation movieclip invisible if is expired
}
try it!
Hope this help!
I have two values coming in, a string in the form StartTime YYYY-MM-DD HH:MM:SS and a Duration in the form HH:MM:SS. from these two values I need to determine the endTime and put it in the same format as the StartTime.
I have tried to make something like
startTimeArray:Array = StartTime.split(/[ -:]/);
var date:Date = new Date(startTimeArray[0], startTimeArray[1]-1, startTimeArray[2], startTimeArray[3], startTimeArray[4], startTimeArray[5] );
but the split of course results in strings and not numbers and I can't figure how to convert all these sections of the time into numbers, and following that I do not see a way to apply math by adding the Duration Date object to the StartTime Date object if I am able to get them properly converted.
Am I going down a good path here? if so, how can I convert an array of strings to numbers and how can I add the duration to starttime? Thanks
const start:String = "2011-04-03 01:39:48";
const startArray:Array = start.split(/[: -]/g);
var startDate:Date = new Date(
startArray[0], startArray[1]-1, startArray[2],
startArray[3], startArray[4], startArray[5]
);
const duration:String = "02:10:10";
const durationArray:Array = duration.split(/:/g);
var durationDate:Date = new Date();
durationDate.setTime(
durationArray[0] * 3600000 + /* hour = 60m * 60s * 1000ms */
durationArray[1] * 60000 + /* minute = 60s * 1000ms */
durationArray[2] * 1000 /* second = 1000ms */
);
var finalDate:Date = new Date();
finalDate.setTime(startDate.time + durationDate.time);
trace(startDate);
trace(durationDate.time);
trace(finalDate);
Outputs:
Sun Apr 3 01:39:48 GMT-0300 2011
7810000
Sun Apr 3 03:49:58 GMT-0300 2011
You will want to split the date and time first and then work from there with the arrays.
var date_:String = StartTime.substring(0,StartTimet.indexOf(" "));
var time_:String = StartTime.substring(StartTime.indexOf(" ")+1, StartTime.length);
trace(date_); // YYYY-MM-DD
trace(time_); // HH:MM:SS
Then split your date into an array
var date_array:Array = StartTime.split("-");
Cast the elements of the array with Number
Then do the same for time but use ":" for the split.
Duration can be split the same way. Then just use normal addition after casting.
var d:Date = new Date(year,month,date,hour,minutes,seconds);
var d_added:Date = new Date(year,month,date,hour+duration_hour,
minutes+duration_minutes,seconds+duration_seconds);
Is there any ActionScript class which represents "durations of time", similar to the TimeDelta class in Python?
Edit: Thanks for the responses. I should clarify a bit, though: I want be able to ask questions like "how many weeks are between date0 and date1" or "let x represent "one day". What is date2 + x?"
I know I can do all this by representing dates as timestamps... But I'm hoping to find something nicer.
I posted a full AS3 port of the .NET TimeSpan class on this question, which sounds exactly like what you need.
// 5 days from new
var ts : TimeSpan = TimeSpan.fromDays(5);
var now : Date = new Date();
var fiveDaysTime : Date = ts.add(now);
// Diff between dates
var d1 : Date = new Date(2009, 1, 1);
var d2 : Date = new Date(2009, 1, 6);
var ts : TimeSpan = TimeSpan.fromDates(d1, d2);
You can use time() in the Date class to get unix era milliseconds and use that for time delta.
If you subtract two dates:
var dateDiff = date1 - date2;
dateDiff will hold the number of milliseconds between the two dates. You can then convert from milliseconds to whatever useful number you like.
I don't think there is a class which measures change in time in Actionscript 3. According to this blog post on Adventures in Actionscript, timing is very inaccurate in the Flash player on the web. That post is pretty informative and has a class called SuperTimer that might help you. You might want to keep this inaccuracy in mind if using solutions posed by Justin Niessner and toastie.