Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dart - How to set the hour and minute of DateTime object

How do I set/change the hour and/or minute of a DateTime object. Similar to Date.setHours(..) in JavaScript.

e.g If i did

var time = DateTime.parse("2018-08-16T11:00:00.000Z"); 

how do I set the hour and minute of time

like image 586
Kingsley CA Avatar asked Oct 03 '18 13:10

Kingsley CA


People also ask

How do I set the time on my DateTime dart?

var newHour = 5; time = time. toLocal(); time = new DateTime(time. year, time. month, time.


1 Answers

var newHour = 5; time = time.toLocal(); time = new DateTime(time.year, time.month, time.day, newHour, time.minute, time.second, time.millisecond, time.microsecond); 

There were discussions to add an update() method that allows to modify specific parts only, but it doesn't look like this has landed.

like image 87
Günter Zöchbauer Avatar answered Sep 24 '22 21:09

Günter Zöchbauer