import static java.lang.System.out;
import java.time.LocalDateTime;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.Duration;
import java.time.Period;
import java.time.DateTimeException;
// or alt: import java.time.*;
public class TestClass {
public static void main(String args[]) {
out.println(LocalDateTime.now());
try{
out.println(Period.of(300_000,10,301));
} catch(ArithmeticException ae) {
}
int q = 1;
while(q< 5){
try{
Thread.sleep(500);
LocalTime t = LocalTime.now().plusHours(q++);
LocalTime v = LocalTime.now().minusHours(q);
out.println(t);
Duration h = Duration.between(t,v); // unexpected output
out.println("h= " + h);
} catch(InterruptedException ie) {
ie.getStackTrace();
} catch(DateTimeException dte) {
dte.getStackTrace();}
}
new TestClass().dateTimePractice();
}
void dateTimePractice() {
LocalDateTime current = LocalDateTime.now();
out.println(current);
int i= 0;
while(i< 5){
try{
Thread.sleep(700);
LocalTime t = LocalTime.now();
System.out.println("The Current Time Is Now:");
out.println(t);
LocalDate day = LocalDate.now();
out.println("The Date is:");
out.println(day);
i++;
if(i>10) break;
} catch(InterruptedException ie) {
out.println(ie.getMessage() );
}
}
}
}
22:08:16.908
h= PT-3H // not what i expected it to do
The Current Time Is Now:
21:08:19.132
The Date is:
2016-02-07
The Current Time Is Now:
21:08:19.834
The Date is:
2016-02-07
The Current Time Is Now:
21:08:20.537
The Date is:
2016-02-07
The Current Time Is Now:
21:08:21.239
The Date is:
2016-02-07
The Current Time Is Now:
21:08:21.942
The Date is:
2016-02-07