Date in Java Example

Posted on Updated on

In Java we can use java.util.Date package or java.util.Calendar to work with Date and time. Let us see some simple examples.

1) java.util.Date

  • Get current Date

    Output

  • Convert String to date

    Output

  • Date formatting using date formatter

    Output

  • Get current date time

    Output

2) java.util.Calendar

  • Get current Date

    Output

  • Convert String to Calendar

    Output

  • Get current date time

    Output

  • Add and subtract from date

    Output

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.