Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: java.lang.IllegalArgumentException: Cannot format given Object as a Date

  1. #1
    Junior Member
    Join Date
    Apr 2014
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default java.lang.IllegalArgumentException: Cannot format given Object as a Date

    Hi All,

    I would like to ask for help inorder to fix the error that I'm encountering. When trying to convert the time zone of a date I encountered the log below.

    java.lang.IllegalArgumentException: Cannot format given Object as a Date

    Here is what my code looks like:

    1. First I will get the date from the email header by the following code.

    String messageDate = (String) mail.headers["Date"];

    Output: Wed, 4 Jun 2014 18:30:05 +0800

    2. Next I will convert the timezone to EST.

    SimpleDateFormat timeZoneConvert = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");

    timeZoneConvert.setTimeZone(TimeZone.getTimeZone(" EST"));

    String l_MailDateEST = timeZoneConvert.format(messageDate.trim());

    Once the code run I encounter the said error.

    Hoping for your help,

    Many Thanks,
    Kenneth


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,296
    Thanks
    180
    Thanked 824 Times in 767 Posts
    Blog Entries
    5

    Default Re: java.lang.IllegalArgumentException: Cannot format given Object as a Date

    Read the API for SimpleDateFormat and the classes it inherits from - to parse a String into a Date object, use the parse method. To convert the Date into a String, use the format method. The call to format(Object object) is inherited from the Format class, and is equivilent to
         format(obj, new StringBuffer(), new FieldPosition(0)).toString();
    and the API for this method states:
    Overrides Format. Formats a time object into a time string. Examples of time objects are a time value expressed in milliseconds and a Date object.

  3. #3
    Junior Member
    Join Date
    Apr 2014
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java.lang.IllegalArgumentException: Cannot format given Object as a Date

    Thank you so much,

Similar Threads

  1. Java Date Format in Date Object
    By Ashr Raza in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 13th, 2012, 09:47 AM
  2. Exception in thread "main" java.lang.IllegalArgumentException: PWC6309: Illegal compi
    By nagaraj200788@gmail.com in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: July 18th, 2012, 04:45 PM
  3. java.lang.IllegalArgumentException: Identifier not found
    By aussiemcgr in forum What's Wrong With My Code?
    Replies: 9
    Last Post: March 9th, 2012, 03:48 AM
  4. java.lang.IllegalArgumentException: im == null!
    By simantoch in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: April 10th, 2011, 02:15 PM
  5. Replies: 2
    Last Post: November 3rd, 2009, 05:28 AM