Current Date and Time
To get current date and time in Dart programming, use the DateTime
class’s constructor DateTime.now()
. The constructor returns a DateTime
instance with current date and time in the local time zone.
Dart Program
In the following program, we get the current date and time using DateTime.now().
main.dart
</>
Copy
void main() {
final now = DateTime.now();
print(now);
}
Output
2022-09-24 08:26:28.645387
Conclusion
In this Dart Tutorial, we learned how to get current date and time using DateTime
class.