0

Any Clues on how to fix this:

SimpleDateFormat df = new SimpleDateFormat("yyyy/mm/dd hh:24mi:ss");

Exception:

Exception in thread "main" java.lang.IllegalArgumentException: Illegal pattern character 'i'
at java.text.SimpleDateFormat.compile(SimpleDateFormat.java:696)
at java.text.SimpleDateFormat.initialize(SimpleDateFormat.java:515)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:464)
at java.text.SimpleDateFormat.<init>(SimpleDateFormat.java:445)
at CopyEJ.CopyEJ.main(CopyEJ.java:105)
4
  • 4
    what are you trying to do? what do you expect 'i' format character to do? Commented Jun 28, 2013 at 13:23
  • can u show us the date string Commented Jun 28, 2013 at 13:24
  • What is the expected result? Commented Jun 28, 2013 at 13:25
  • Your date pattern looks like Oracle database and not like Java... Commented Jun 28, 2013 at 13:26

5 Answers 5

7

Your pattern string is not following the java standard. This should work:

SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Sign up to request clarification or add additional context in comments.

Comments

5

Your date format pattern string contains the invalid sequence 24mi.

change to:

SimpleDateFormat("yyyy/MM/dd HH:mm:ss");

note: the Big letter "HH" means 24 hours: e.g 23:59:00
while "hh" is 12 hours format: 11:59:00

Comments

3

As pointed by others, the pattern string is not correct, and can be as showed by others "yyyy/MM/dd HH:mm:ss".

Refer the java documentation for looking up the available pattern letters that could be used for formatting a date.

Snippet from the above link

Letter  Date or Time Component  Presentation    Examples
G   Era designator  Text    AD
y   Year    Year    1996; 96
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 in week     Text    Tuesday; Tue
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

Comments

1

If you want hours in 24 hour format Use this

    DateFormat df=new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    Date dd=new Date();
    System.out.println(df.format(dd));

Comments

0

java.time

Updating for the java.time classes that supplanted the terribly-flawed legacy date-time classes SimpleDateFormat, Date, Calendar, etc.

Your formatting pattern was wrong on two counts:

  • Ignoring case-sensitivity (mm versus MM)
  • Invalid formatting codes (I)

The formatting codes is java.time are similar, but not exactly the same as the legacy classes. Be sure to study the Javadoc carefully.

DateTimeFormatter f = DateTimeFormatter.ofPattern ( "uuuu/MM/dd HH:mm:ss" ) ;

Capture the current moment.

ZoneId z = ZoneId.of ( "America/Edmonton" ) ;  // Or ZoneId.systemDefault()
ZonedDateTime zdt = ZonedDateTime.now ( z ) ;

Use that formatter to generate text.

String output = zdt.format ( f ) ;

See this code run at Ideone.com.

2025/07/23 15:55:24

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.