Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Get Current Date in Java

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 275
    Comment on it

    Hello, We need current date in many situations.
    Here I am writing different ways to get current date in java.
    1. Get current date using java.util.Date.

    Date currentDate = Date();
    System.out.println(Current date : +currentDate);
    O/P:
    Current date: Mon Oct 19 08:22:02 IST 2015
    


    1. Get current date using java.util.Date but using System currenTimeMillis() method
    long timeLng=System.currentTimeMillis();
    Date currentDate=new Date(timeLng);
    System.out.println(Current date: +currentdate);
    O/P:
    Current date: Mon Oct 19 08:22:02 IST 2015
    


    1. Using java.sql.Date
    long lngTime=System.currentTimeMillis();
    Date currentDate=new Date(lngTime);
    System.out.println(Current date: );
    Output:
    Current date: 2015-10-19
    


    1. Get current date using Calendar class
    Date currentDate= Calendar.getInstance().getTime();
    System.out.println(Current date: +currentDate);
    O/P:Current date: Mon Oct 19 08:22:02 IST 2015

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: