Parsing date with SimpleDateFormat

by vincent.gann...@gmail.com » Sat, 28 Mar 2009 01:39:54 GMT


Sponsored Links
 Hi all,

I'm trying to parse the following date string "Fri, 12 Jan 2007
10:00:00 +0100" using SimpleDateFormat. Here is my code :

Date date;
String pubDate = "Fri, 12 Jan 2007 10:00:00 +0100";
SimpleDateFormat format = new SimpleDateFormat("EEE, dd MM yyyy
HH:mm:ss zzz");
try
{
    date = format.parse(pubDate);
}
catch(ParseException e) { }

This code raises the ParseException instead of returning the
corresponding date object.

I tried a huge amount of other date formats to create the
SimpleDateFormat but none has worked.

Any guess? Thanks.
--~--~---------~--~----~------------~-------~--~----~



Parsing date with SimpleDateFormat

by Mike Collins » Tue, 31 Mar 2009 05:37:44 GMT


 my dates come in looking like this  "2004-08-04T19:09:02.768Z"

and I parse them like this

SimpleDateFormat dateFormater = new SimpleDateFormat("yyyy-MM-
dd'T'HH:mm:ss'.000Z'");
dateFormater.setTimeZone(TimeZone.getTimeZone("GMT"));
Date d = dateFormater.parse(s);

Try creating a Date object and making a string out of it via the date
format,
if what you get is what you expect for input you should be ok, if not
something
has to be adjusted.

  mike


On Mar 27, 10:39am, "vincent.gann...@gmail.com"


--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Other Threads

1. how to determine if a file exists in a directory with FileNotFoundException

I've been working with Eclipse ADT for about 2 months. In that time I
have a small utility that allows me to select an IP Address and Port,
and then send a file to that combo. The utility works as intended, but
when I type in the wrong file name, the application hangs.

@Override
   public void run() {
      if (data != null) {
         this.send(data);
      } else if (this.file != null) {
         if (file.exists()) {
            this.send(file);
         } else {
            transferError = new FileNotFoundException("The specified
file could not be found");
         }
      }
   }

I've even tried to do the following in hopes that one or the other
would throw, but I am unsuccessful in both.

public void run() {
      if (data != null) {
         this.send(data);
      } else if (this.file != null) {
         if (file.exists()) {
            this.send(file);
         } else {
            transferError = new FileNotFoundException("The specified
file could not be found");
         }
      }try {
         throw new Exception("blah blah blah");
      } catch (Exception e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }
   }

I've jockeyed around the exception, I've added the one above, I've
tried placing it in different places, and all unsuccessful. Again, I'm
exceptionally new to this, and got here from basically mincing various
tcp client codes. Aside of creating a way to throw the exception
correctly, please help me understand why the first one isn't working
and why the one you suggest is.

-- 

2. Push notifications

Hi,

is there any app for Facebook/Twitter that fully supports push
notifications? Is it hard to build such application using c2dm?

-- 

3. MiFare Classic detection

4. How to refresh a "Form"

5. Samsung Galaxy S calendar app on Sprint allows starting "Google Maps" or "Sprint Navigation" only to "Complete action using" when clicking on Location.

6. Still receiving sensor events after unregisterListener

7. Java