Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting starting time of the particular date in dart

Hi I am trying to get the start time as current date 12:00 AM as my fromTime

DateTime toTime= new DateTime.now();
DateTime fromTime= toTime.subtract(new Duration(days: 1));

By above I am getting fromTime value as curent time - 24hrs, but I want fromTime as current date 12 AM

output what I am getting is

2019-09-30 14:25:36.105 //toTime
2019-09-29 14:25:36.105 //fromTime

expected output:

2019-09-30 14:25:36
2019-09-30 00:00:00

help me out to get the above,Thanks.

like image 413
mark Avatar asked Sep 05 '25 03:09

mark


1 Answers

Did you mean like this:

  DateTime toTime= new DateTime.now();
  DateTime fromTime= new DateTime(toTime.year, toTime.month, toTime.day);
  print(toTime);
  print(fromTime);

output:

2019-09-30 17:15:20.294
2019-09-30 00:00:00.000
like image 157
Tokenyet Avatar answered Sep 09 '25 07:09

Tokenyet