Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Convert Datetime to Unix Timestamp in Haxe

How to convert Datetime to Unix timestamp in Haxe

🎈 🎈 🎈
+1

    class Main {
        static function main() {
            // Convert Date to Unix timestamp
            var date:Date = Date.fromString("2011-01-08 11:25:33");
            var unixTimestamp:Float = date.getTime() / 1000;
            
            trace("Unix Timestamp: " + unixTimestamp);
        }
    }            
        

Output:
Unix Timestamp: 1294485933
Example only. There may be multiple ways to perform this operation.

Code Explanation

In this Haxe snippet, a Date object is created using Date.fromString for the date '2011-01-08 11:25:33'.
The getTime() method is used to get the number of milliseconds since the Unix epoch. This value is divided by 1000 to convert it to seconds, which is the Unix timestamp format.
The result will be the Unix timestamp '1294485933'.



Other useful Haxe date functions

Function Description Example
Date.now() Returns the current date and time as a Date object. Date.now() returns 2024-08-28 12:34:56
Date.fromTime() Creates a Date object from the number of milliseconds since the Unix epoch. Date.fromTime(1589530245000) returns 2020-05-15 08:10:45
getTime() Returns the number of milliseconds since January 1, 1970 for a Date object. date.getTime() returns 1589530245000
Date.fromString() Parses a string representation of a date into a Date object. Date.fromString("2020-05-15 08:10:45") returns 2020-05-15 08:10:45
Date.toString() Returns a string representation of the date in ISO 8601 format. date.toString() returns 2020-05-15T08:10:45
Date.fromUnix() Parses a Unix timestamp (in seconds) into a Date object. Date.fromUnix(1589530245) returns 2020-05-15 08:10:45
DateTools.format() Formats a Date object into a custom string format. DateTools.format(date, "%Y-%m-%d %H:%M:%S") returns 2020-05-15 08:10:45
Current Unix Timestamp SECONDS SINCE JAN 01 1970

Current UTC Time
2025-08-20
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder
Ad Banner Placeholder