I'm converting a VB.Net program to Java and I have to convert following line
Dim s = Now.ToString("yyyy-MM-dd")
I have written following Java code
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String s = sdf.format(d);
that I can write on one line
String s = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
What is the shorter code in Java that works in Java 6 and greater ?
Is there some Java codes that generates date formatted string in calling a method of Date object (example: Date.format("yyyy-MM-dd")
) ?