Hello,
We need current date in many situations.
Here I am writing different ways to get current date in java.
1. Get current date using java.util.Date.
Date currentDate = Date();
System.out.println(Current date : +currentDate);
O/P:
Current date: Mon Oct 19 08:22:02 IST 2015
- Get current date using java.util.Date but using System currenTimeMillis() method
long timeLng=System.currentTimeMillis();
Date currentDate=new Date(timeLng);
System.out.println(Current date: +currentdate);
O/P:
Current date: Mon Oct 19 08:22:02 IST 2015
- Using java.sql.Date
long lngTime=System.currentTimeMillis();
Date currentDate=new Date(lngTime);
System.out.println(Current date: );
Output:
Current date: 2015-10-19
- Get current date using Calendar class
Date currentDate= Calendar.getInstance().getTime();
System.out.println(Current date: +currentDate);
O/P:Current date: Mon Oct 19 08:22:02 IST 2015
0 Comment(s)