-5

java.text.ParseException: Unparseable date: "2014-01-15 00:003:00" ecxception is throwing please shorout my peoblem Thanks import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*;

public class Dd {

  public static void main(String args[]) throws ParseException {

String s1="2014-01-15 00:003:00";

SimpleDateFormat sdf=new SimpleDateFormat("yyyy--MM-dd h:mm:ss");
   try{

Date date =sdf.parse(s1);
      SimpleDateFormat sdf1=new SimpleDateFormat("dd--MMM-dd H:mm:ss"); 
      String s3=sdf1.format(date);
System.out.println(s3);

 }
   catch (ParseException e) {
       System.out.println(e);
  }

 }
}
user3198494
  • 3
  • 1
  • 7

2 Answers2

0

You can use SimpleDateFormat

The following pattern letters are defined (all other characters from 'A' to 'Z' and from 'a' to 'z' are reserved):

Letter  Date or Time Component  Presentation    Examples
G   Era designator  Text    AD
y   Year    Year    1996; 96
Y   Week year   Year    2009; 09
M   Month in year   Month   July; Jul; 07
w   Week in year    Number  27
W   Week in month   Number  2
D   Day in year Number  189
d   Day in month    Number  10
F   Day of week in month    Number  2
E   Day name in week    Text    Tuesday; Tue
u   Day number of week (1 = Monday, ..., 7 = Sunday)    Number  1
a   Am/pm marker    Text    PM
H   Hour in day (0-23)  Number  0
k   Hour in day (1-24)  Number  24
K   Hour in am/pm (0-11)    Number  0
h   Hour in am/pm (1-12)    Number  12
m   Minute in hour  Number  30
s   Second in minute    Number  55
S   Millisecond Number  978
z   Time zone   General time zone   Pacific Standard Time; PST; GMT-08:00
Z   Time zone   RFC 822 time zone   -0800
X   Time zone   ISO 8601 time zone  -08; -0800; -08:00
lichengwu
  • 4,277
  • 6
  • 29
  • 42
0

Try this..

String s1 = "2013-01-15 8:00:03";
    SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd h:mm:ss");
    try {
        Date dt=sdf.parse(s1);//converting to date
         SimpleDateFormat sdf1=new SimpleDateFormat("dd-MMM-yyyy h:mm:ss");
         String s2=sdf1.format(dt);//formating to new format string
         System.out.println(s2);
    } catch (ParseException ex) {

    }

//new answer

public class Dd {

    public static void main(String args[]) throws ParseException {

        String s1 = "2014-01-15 00:003:00";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        try {
            Date date = sdf.parse(s1);
            SimpleDateFormat sdf1 = new SimpleDateFormat("dd-MMM-yyyy hh:mm:ss");
            String s3 = sdf1.format(date);
            System.out.println(s3);

        } catch (ParseException e) {
            System.out.println(e);
        }

    }
}
Myth
  • 446
  • 7
  • 18
  • java.text.ParseException: Unparseable date: is throwing – user3198494 Jan 16 '14 at 05:32
  • have you add these imports.. import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; – Myth Jan 16 '14 at 05:34
  • i have import all package – user3198494 Jan 16 '14 at 05:35
  • can yon check my code – user3198494 Jan 16 '14 at 05:37
  • public class Dd { public static void main(String args[]) throws ParseException {String s1="2014-01-15 00:003:00"; SimpleDateFormat sdf=new SimpleDateFormat("yyyy--MM-dd h:mm:ss"); try{Date date =sdf.parse(s1); SimpleDateFormat sdf1=new SimpleDateFormat("dd--MMM-dd H:mm:ss"); String s3=sdf1.format(date); System.out.println(s3); } catch (ParseException e) { System.out.println(e); } – user3198494 Jan 16 '14 at 05:41
  • sir i have edited my question u can find out my problem from there – user3198494 Jan 16 '14 at 05:49
  • you can check out my new answer below the first one.. and see the difference between my code and yours.. you have put some extra "-" in youtr date formats – Myth Jan 16 '14 at 05:54
  • i am getting this output 15-Jan-15 12:03:00 and my desired output is 15-jan-2014 12:03:00 – user3198494 Jan 16 '14 at 06:00
  • sorry mistake from my side you can check it out now.. i have changed the date format – Myth Jan 16 '14 at 06:01