datetime - How to count days between string date java -
i have dates in variable , b, this. string = "2016-01-28 21:50"; string b = "2016-01-31 21:49";
how count how many days there between variable , b?
in java 8, can use chronounit achieve this.
here example code snippet consider.
import java.time.localdate; import java.time.format.datetimeformatter; import java.time.temporal.chronounit; public class daysinbetween { public static void main(string[] args) { string = "2016-01-28 21:50"; string b = "2016-01-31 21:49"; final datetimeformatter fmt = datetimeformatter.ofpattern("yyyy-mm-dd hh:mm"); final localdate d1 = localdate.parse(a, fmt); final localdate d2 = localdate.parse(b, fmt); final long daysinbetween = chronounit.days.between(d1, d2); system.out.println("number of days in between:" + daysinbetween); } }
Comments
Post a Comment