Answers for "find the number of days between datetime in java"

0

calculate days between two dates in java

import java.util.Date;
import java.text.SimpleDateFormat;
class Example{
   public static void main(String args[]){
	 SimpleDateFormat myFormat = new SimpleDateFormat("dd MM yyyy");
	 String dateBeforeString = "31 01 2014";
	 String dateAfterString = "02 02 2014";

	 try {
	       Date dateBefore = myFormat.parse(dateBeforeString);
	       Date dateAfter = myFormat.parse(dateAfterString);
	       long difference = dateAfter.getTime() - dateBefore.getTime();
	       float daysBetween = (difference / (1000*60*60*24));
               /* You can also convert the milliseconds to days using this method
                * float daysB
Posted by: Guest on May-19-2020

Code answers related to "find the number of days between datetime in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language