"Build a Self-Destructing Message Android App" was retired on June 13, 2016. You are now viewing the recommended replacement.

Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

adding a week upon calling Date() method

hi,

    String checkout = String.format("Book successfully checked out on %s", new Date());
    System.out.println(checkout);

this will print out the date and time of when the code is called. What i want to do is have another line that says Book is due on %s, new Date() + a week

and also to store that new date so i can check if the book was returned on time or not

however i got no idea how to do this.. on second thought, is this even possible? otherwise is there any alternative way?

thanks

1 Answer

i figured out how to do it and its pretty cool :)

http://docs.oracle.com/javase/8/docs/api/

its under the java.time.LocalDateTime package

if anyone wants to see how i did it:

LocalDateTime time = LocalDateTime.now();
        String checkout = String.format("Book successfully checked out is due a week later on %s", time.plusWeeks(1) );
        System.out.println(checkout);