tomaszkubacki tomaszkubacki - 1 year ago 101
Dart Question

How to get first day of previous month Datetime with Dartlang

I want to get first day of previous month in Dart as DateTime.
Below code is working correctly even for x = 1 (passing 0 as month)

print(new DateTime(2016,x-1,1));

but is it by design or I should not relay on it ?

lrn lrn
Answer Source

It is by design. The DateTime constructor you are using allows overflow and underflow on both days and months. A month value less than one means a month prior to January, which is a month in a previous year. Likewise a day value of less than one is a day in a previous month.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download