How to format Date and Time in Java

In Java we constantly need to format date and time. so for that we can use the class SimpleDateFormat. So i will show how to get a Date instance and format it.

Calendar calendar = Calendar.getInstance();
Date date = calendar.getTime();

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String outputString = formatter.format(date)
Share on Google Plus

About Admin

I am a Java and Android developer and a science enthusiast.I Like to explain complex things in simple language so anybody even without a graduation in computer science or Electronics can understand the concepts easily.

0 comments:

Post a Comment