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. Best way to expose my Activity to third parties?

Hi all,

I made an Activity that I'd like to let others call by passing me a
url. I expect a url like this:

  http://www.mysite.com/input/user-supplied-data

and my activity intent filter looks like this:

  <intent-filter>
    <action android:name="android.intent.action.VIEW"></action>
    <category android:name="android.intent.category.DEFAULT"></
category>
    <category android:name="android.intent.category.BROWSABLE"></
category>
    <data android:host="www.mysite.com" android:pathPrefix="/input/"
android:scheme="http"></data>
</intent-filter>

This works well, users can invoke my activity like this:

  Intent intent = new Intent(Intent.ACTION_VIEW,
    Uri.parse("http://www.mysite.com/input/" + "orange"));
  startActivity(intent);

and android will pop up a chooser dialog asking if I want to open the
data in either the native browser, or my app.

Some third party developers that want to use my activity might not
want the intermediate step of showing the chooser dialog though - they
know they want to use my activity, and only my activity, and send the
user there directly from their app. I added a unique category string
to my intent filter like this, so that third party developers can
reference it:

  <category android:name="com.me.test.intent.category.VIEWTEST" />

so now a third party developer can do this:

  Intent intent = new Intent(Intent.ACTION_VIEW,
    Uri.parse("http://www.mysite.com/input/" + "orange"));
  intent.addCategory("com.me.test.intent.category.VIEWTEST");
  startActivity(intent);

and since my app should be the only one declaring that category in an
intent filter, android will just move the user to it directly.

Is this a good practice, or is there some better way to allow third
party developers to call my activity 'directly'?

This does seem to work, I just don't know if this practice of using a
custom category is frowned upon. In the end, my intent filter looks
like this:

  <intent-filter>
    <action android:name="android.intent.action.VIEW"></action>
    <category android:name="com.me.test.intent.category.VIEWTEST" />
    <category android:name="android.intent.category.DEFAULT"></
category>
    <category android:name="android.intent.category.BROWSABLE"></
category>
    <data android:host="www.mysite.com" android:pathPrefix="/input/"
android:scheme="http"></data>
</intent-filter>

Thanks

-- 

2. Camera on HTC Hero: Calling camera.autoFocus(...) gives a IOException .. ?



At the same time, at least I don't know how to answer it. I have not
seen this error, but, then again, I have not tried auto-focus on the
Hero. To be honest, I wasn't aware it was running an Android version
where auto-focus was available.

Do you have the <uses-feature> element in your manifest to say you need
auto-focus?

If you can publish a project that demonstrates the error, upload it
along with a description of the symptoms to http://b.android.com. If you
think of it, post a link to the issue report here. I have a couple of
Heros, though they're on kinda squirrelly ROM versions IIRC, so I'm not
sure my tests will be definitive.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Android Training in US: 26-30 April 2010: http://onlc.com

-- 

3. Camera on HTC Hero: Calling camera.autoFocus(...) gives a IOException .. ?

4. Broadcast intent for USB power?

5. Oot siapa aja yg ke acara isat android?

6. Tracking locations using Sensor Manager

7. how to fastboot flash radio, .img file