Current Unix Timestamp SECONDS SINCE JAN 01 1970

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

How to convert Unix timestamp to Datetime in Dart

🎈 🎈 🎈
+1

    void main() {
        int unixTimestamp = 1192609211;  // Example Unix timestamp
        DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(unixTimestamp * 1000, isUtc: true);
        
        print('Converted Date: $dateTime');
        }
        

Output:
Converted Date: 2007-10-17 08:20:11
Example only. There may be multiple ways to perform this operation.

Code Explanation

To convert the Unix timestamp '1192609211' (representing 2007-10-17 08:20:11 UTC) to date in Dart it is passed to DateTime.fromMillisecondsSinceEpoch() after multiplying it by 1000 to convert it from seconds to milliseconds.
The isUtc: true flag indicates that the time is in UTC. The function converts the timestamp into a DateTime object, which is then printed in a human-readable format.



Other useful Dart date functions

Function Description Example
DateTime.now() Returns the current date and time based on the local time zone. DateTime.now() returns 2024-08-28 12:34:56
DateTime.utc() Creates a DateTime object in UTC for the specified year, month, day, hour, minute, and second. DateTime.utc(2022, 5, 15, 8, 30, 45) returns 2022-05-15 08:10:45 UTC
DateTime.fromMillisecondsSinceEpoch() Creates a DateTime object from the number of milliseconds since January 1, 1970 (the Unix epoch). DateTime.fromMillisecondsSinceEpoch(1652602245000) returns 2022-05-15 08:10:45 UTC
DateTime.parse() Parses a string into a DateTime object. DateTime.parse("2022-05-15T08:10:45Z") returns 2022-05-15 08:10:45 UTC
millisecondsSinceEpoch Returns the number of milliseconds since January 1, 1970 for a DateTime object. dateTime.millisecondsSinceEpoch returns 1652602245000
toIso8601String() Converts a DateTime object to a string in ISO 8601 format. dateTime.toIso8601String() returns 2022-05-15T08:10:45Z
add() Adds a Duration to a DateTime object. dateTime.add(Duration(days: 5)) returns 2022-05-20 08:10:45
subtract() Subtracts a Duration from a DateTime object. dateTime.subtract(Duration(days: 5)) returns 2022-05-10 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