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

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 106
    Comment on it

    Date Class in java:

    There is a Date class in java under java.util package which can be used to print the current dates. There can be various ways to print the current date. Lets see with the help of example:

    import java.util.Date;
    
    public class DateDemo {
    	
    	public static void main(String args[]) {
    	
    	Date date=new Date();  // Simple way of getting date
    	System.out.println(date);  
    
    	
    	long milliSeconds=System.currentTimeMillis();  
    	date=new Date(milliSeconds);  // passing the milliseconds since January 1970
    	System.out.println(date);  
    	
    	
        date=java.util.Calendar.getInstance().getTime();  // printing with the help of Calendar object
    	System.out.println(date);  
    }
    }

     

    So the output will be:

    Wed Mar 30 17:01:33 IST 2016
    Wed Mar 30 17:01:33 IST 2016
    Wed Mar 30 17:01:33 IST 2016

     

 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: