Reputation: 369
I have a timestamp which in which I want to add 48 hours or 2 days. How can I add?
Upvotes: 0
Views: 1700
Reputation: 3611
void main() {
var date1 = DateTime.utc(2020, 10, 28, 0, 0, 0);
date1 = date1.add(Duration(days: 2));
print(date1);
}
date1 = date1.add(Duration(days: 2)); //days
date1 = date1.add(Duration(hours: 48)); //hours
Upvotes: 2
Reputation: 2793
The DateTime
instance can be created from two methods -
If you are getting seconds in timestamp, then convert those seconds to milliseconds & create the DateTime object:
// Pass milliseconds to this constructor
DateTime dateTime = DateTime.fromMillisecondsSinceEpoch(milliseconds);
// Add 2 days to the dateTime object
dateTime.add(Duration(days: 2));
Upvotes: 1