In Java we have Date class available in java.util package which encapsulates the current date and time.
The Date class have two constructors mentioned below:
1 Date( )
This constructor initializes the object with the current date and time. This doesn’t require any argument.
2 Date(long millisec)
We need to provide an argument to this constructor that equals the number of milliseconds that have elapsed since midnight, January 1, 1970
Below is a program to get current date and time:
It is very easy to get current date and time in Java. We need to create Date object with toString() method to print current date and time as follows:
[java]
import java.util.Date;
public class CurrentSystemDate{
public static void main(String args[]) {
// Instantiate a Date object
Date date = new Date();
// display time and date using toString()
System.out.println(date.toString());
}
}
[/java]
OUTPUT:
on February 03 10:01:47 CDT 2016
Related Article
About How to get current date and time of the system In Java.
<figure class="wp-block-table is-style-stripes">
<table>
<tbody>
<tr>
<td><strong>Project Name:</strong></td>
<td>How to get current date and time of the system</td>
</tr>
<tr>
<td><strong>Language/s Used:</strong></td>
<td>JAVA</td>
</tr>
<tr>
<td><strong>Database:</strong></td>
<td>None</td>
</tr>
<tr>
<td><strong>Type:</strong></td>
<td>Desktop Application</td>
</tr>
<tr>
<td><strong>Developer:</strong></td>
<td>IT SOURCECODE</td>
</tr>
<tr>
<td><strong>Updates:</strong></td>
<td>0</td>
</tr>
</tbody>
</table><figcaption><em><strong>How to get current date and time of the system In Java</strong>– Project Information<br>
</em></figcaption></figure>