DateTime class provides ‘getMillis’ method which return the milliseconds of the datetime instant from the Java epoch. Using ‘getMillis’ method, you can find the difference in milliseconds.
Example
DateTime today = new DateTime();
DateTime tomorrow = today.plusDays(1);
long diffInMillis = tomorrow.getMillis() - today.getMillis();
DateTimeDiffInMilliseconds.java
package com.sample.app.joda;
import org.joda.time.DateTime;
public class DateTimeDiffInMilliseconds {
public static void main(String args[]) {
DateTime today = new DateTime();
DateTime tomorrow = today.plusDays(1);
long diffInMillis = tomorrow.getMillis() - today.getMillis();
System.out.println("Difference between today and tomorrow in milliseconds: " + diffInMillis);
}
}
Output
Difference between today and tomorrow in milliseconds: 86400000
No comments:
Post a Comment