Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,939 questions

51,876 answers

573 users

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

...