Problem :How to get system date from operating system?Solution :There is a class java.util.Date that has all date related methods.Program :Step 1 - CodingCreate a text file c:\sunilos\TestDate.java and copy below contents.import java.util.Date; /* * A program which shows the current date. */ public class TestDate { public static void main(String[] args) { Date d= new Date(); System.out.println("Todays date is " +d); } } Step 2 - Deployment
Step 3 - Testing
OutputTodays date is Mar 21, 2009FAQWhat is Date class?The classDate represents a specific instant
in time, with millisecond precision.Why do I import java.util.Date?Java organizes its classes into different packages like java.lang, java.util, java.io etc. Classes those are exist in other than java.lang packages are required to be imported to use them. Since Date class belongs to java.util package so you need to import this package with help of below commandsimport java.util.*; or import java.util.Date; <<Previous | Next>> |