Date Time in Openfl

Hi,

In AS3 there were some methods like my_date.setTime(10000); which are not in Haxe Openfl.

Also in AS3 we can make a Date object like this :

var my_date:Date = new Date();

but in OpenFl i need to provide all the parameters to make an object.

How to achieve same thing here in Open Fl.

Adobe Example
    var my_date:Date = new Date(2004,4,15,8,0,0); 
    var myDate_num:Number = my_date.getTime(); // convert my_date to milliseconds 
    myDate_num += 30 * 60 * 1000; // add 30 minutes in milliseconds 
    my_date.setTime(myDate_num); // set my_date Date object 30 minutes forward 
    trace(my_date.getFullYear()); // output: 2004 
    trace(my_date.getMonth()); // output: 4 
    trace(my_date.getDate()); // output: 15 
    trace(my_date.getHours()); // output: 8 
    trace(my_date.getMinutes()); // output: 30

thanks

Check this out:

Your example could look like that with static extensions

// After imports
using DateTools;

// In your code
var my_date:Date = new Date(2004,4,15,8,0,0); 
my_date = my_date.delta(30 * 60 * 1000);
trace(my_date);
trace(my_date.format("%H:%M"));

Or without using

var my_date:Date = new Date(2004,4,15,8,0,0); 
my_date = DateTools.delta(my_date, 30 * 60 * 1000);
trace(my_date);
trace(DateTools.format(my_date, "%H:%M"));

Main.hx:17: 2004-05-15 08:30:00
Main.hx:18: 08:30

1 Like

thank you for the link and the solution, lol my bad i missed it :smiley: that cook book is always opened in one of the Tabs all the time and i forgot it completely.