Monday 6 November 2017

java - How to display date in dd/mm/yyyy format?





I am to new to Java. I want to display date in
dd/mm/yyyy format. When I print date using new
Date()
function it gives me Sting which I don't want. Say I want to print
today's date it gives me Sat Jan 24 08:17:41 IST 2015 but I
want output as 24/1/2015



Answer




Use href="http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html"
rel="nofollow">SimpleDateFormat:



SimpleDateFormat
sdf = new SimpleDateFormat("dd/MM/yyyy");
String date = sdf.format(new
Date());

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...