0

Hi i have a date varilable here date is in following formate:

Fri Nov 06 23:59:59 IST 2015

Now i want to convert thi date in below format

2015-11-06 23:59:59

I am using this but not working:

 SimpleDateFormat sdf=new SimpleDateFormat(fromDate);
                Date currentdate;
                currentdate=sdf.parse(fromDate);
                System.out.println("TestDATE"+currentdate);

How can I convert?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Shakti Sharma
  • 2,131
  • 3
  • 18
  • 23
  • _In which way_ is it not working? Please specify and also add input and output you get. Btw, you should pass a format string to the `SimpleDateFormat` constructor, not the date itself. – Thomas Nov 12 '15 at 08:13
  • Is the input a date or a string? A date type has no format. Plase show a minimal runable example – Jens Nov 12 '15 at 08:15
  • maybe it's a duplicate Question please check those answer: http://stackoverflow.com/questions/31624828/java-convert-date-format And http://stackoverflow.com/questions/4216745/java-string-to-date-conversion – Mourad BENKDOUR Nov 12 '15 at 08:34

2 Answers2

0

Have you read SimpleDateFormat?

Your fromPattern needs to be: EEE MMM dd HH:mm:ss zzz yyyy and toPattern - yyyy-MM-dd HH:mm:ss.

agad
  • 2,192
  • 1
  • 20
  • 32
0

Date is a container for the number of milliseconds since the Unix epoch ( 00:00:00 UTC on 1 January 1970).

It has no concept of format.

please check those answer: Java convert date format

And

Java string to date conversion

Community
  • 1
  • 1
Mourad BENKDOUR
  • 879
  • 2
  • 9
  • 11