How to get the current (now) date and time value in Java

6 Answers

0 votes
package javaapplication1;

import java.text.*;
import java.util.*;

public class JavaApplication1 
{
    public static void main(String[] args) 
    {
        try
        {
            DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
            Date date = new Date();
            System.out.println(dateFormat.format(date)); // 19/06/2015 11:06:29
        }
        catch (Exception e)
        {
            System.out.println(e.toString());
        }  
    }
}

/*

run:

19/06/2015 11:06:29

*/

 



answered Jun 19, 2015 by avibootz
0 votes
package javaapplication1;

import java.text.*;
import java.util.*;

public class JavaApplication1 
{
    public static void main(String[] args) 
    {
        try
        {
            DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
            Calendar calendar = Calendar.getInstance();
            System.out.println(dateFormat.format(calendar.getTime())); // 19/06/2015 11:11:15
        }
        catch (Exception e)
        {
            System.out.println(e.toString());
        }  
    }
}

/*

run:

19/06/2015 11:11:15

*/

 



answered Jun 19, 2015 by avibootz
0 votes
package javaapplication1;

import java.text.DateFormat;
import java.util.Calendar;
import java.text.SimpleDateFormat;


public class JavaApplication1 
{
    public static void main(String[] args) 
    {
        try
        {
            DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
            Calendar calendar = Calendar.getInstance();
            System.out.println(dateFormat.format(calendar.getTime())); // 19/06/2015 11:13:06
        }
        catch (Exception e)
        {
            System.out.println(e.toString());
        }  
    }
}

/*

run:

19/06/2015 11:13:06

*/

 



answered Jun 19, 2015 by avibootz
0 votes
package javaapplication1;

import java.util.Date;

public class DateTest {
    public static void main(String[] args) {
	    Date now = new Date();
	    System.out.println(now);
    }
}

/*
run:

Fri Jan 08 08:31:17 IST 2016

*/

 



answered Jan 8, 2016 by avibootz
edited Jan 8, 2016 by avibootz
0 votes
package javaapplication1;

public class DateTest {
    public static void main(String[] args) {
	    java.util.Date now = new java.util.Date();
	    System.out.println(now);
    }
}

/*
run:

Fri Jan 08 08:34:36 IST 2016

*/

 



answered Jan 8, 2016 by avibootz
0 votes
package javaapplication1;

import java.util.*;

public class DateTest {
    public static void main(String[] args) {
	    Calendar calendar = Calendar.getInstance();
        Date date =  calendar.getTime();
        System.out.println(date);
    }
}

/*
run:

Fri Jan 08 08:36:27 IST 2016

*/

 



answered Jan 8, 2016 by avibootz

Related questions

...