ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

Home » Java Date & Time programs

How to get current system date and time in Java?

Get current system date and time in Java: In this program, we are getting the system’s current date and time and printing in full format.

Steps to get current system date and time in Java:

  • Include java.util.Date package in the program.
  • Create an object of Date class.
  • Print the object of Date class in string format.

Consider the program:

/*java program to get current system date and time*/

//package to class Date class
import java.util.Date;

public class GetSystemDateTimePrg 
{
	public static void main(String args[])
	{
		//creating object of Date class
		Date dt=new Date();
		//printing the date and time 
		System.out.print("Current system date and time is: " + dt.toString());
	}
}

Output

Current system date and time is: Mon Jul 13 20:56:09 IST 2015
ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.