0

Hi,

I'm unable to change the date format in java. I'm given the code as follow.

java.util.Date date = new Date();

But it displays like july 17 13:01:43 GT 51:25 2010
But i need only this format july 17 13:01:43 2010
Can u pls help on this?

2
Contributors
2
Replies
5
Views
7 Years
Discussion Span
Last Post by TejaDharma
1

Your code given complete date,time and everything. it is a default format.
The below code is exactly reach your requirement

java.util.Date date = new java.util.Date();
DateF=" " + java.text.DateFormat.getDateTimeInstance().format(dateFormat);

And the second approach is you can change your format by ur self

java.text.DateFormat dateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd");
java.util.Date date = new java.util.Date();
DateF=dateFormat.format(date);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.