-
Notifications
You must be signed in to change notification settings - Fork 2
Home
Nguyen Van Tra edited this page Jan 25, 2018
·
2 revisions
Welcome to the Java-OOP-Tutorial wiki!
private LocalDateTime convertStringToDateISO(String dateStr) {
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
LocalDateTime result = LocalDateTime.parse(dateStr, format);
return result;
}
private int getSeconds(LocalDateTime fromDateTime, LocalDateTime toDateTime) {
LocalDateTime tempDateTime = LocalDateTime.from(fromDateTime);
long seconds = tempDateTime.until(toDateTime, ChronoUnit.SECONDS);
return (int) seconds;
}
public static void main(String[] args) {
Example mExample = new Example();
String fromDateTime = "2011-11-02T02:25:00.208Z";
String toDateTime = "2011-11-02T02:30:00.208Z";
int seconds = mExample.getSeconds(mExample.convertStringToDateISO(fromDateTime),
mExample.convertStringToDateISO(toDateTime));
System.out.println(seconds);
}