文字列を日付に変換するのに 2 時間以上かかりました。私が間違っていることを理解していませんか?
ここに私が受け取る私の文字列の日付があります= "Thu, 31 Jan 2013 10:48:58 GMT"
これが私のコードです:
try {
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yy hh:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
Date d = new Date();
d = sdf.parse(expire);
long timestamp = d.getTime();
return timestamp;
} catch (ParseException e) {
e.printStackTrace();
}
私はいつも例外を受け取ります。単純な日付形式が間違っていると思います。どれでも役に立ちます。
私のlogcat:
01-30 11:41:03.453: W/System.err(8577): java.text.ParseException: Unparseable date: "Thu, 31 Jan 2013 10:48:58 GMT" (at offset 0)
01-30 11:41:03.453: W/System.err(8577): at java.text.DateFormat.parse(DateFormat.java:626)
01-30 11:41:03.453: W/System.err(8577): at fr.haploid.lrucachelibrary.ImageFetcher.getTimestamp(ImageFetcher.java:305)
01-30 11:41:03.453: W/System.err(8577): at fr.haploid.lrucacheprotoptvo.activities.ImageGridActivity$ImageAdapter.getView(ImageGridActivity.java:152)
01-30 11:41:03.453: W/System.err(8577): at android.widget.AbsListView.obtainView(AbsListView.java:2255)
01-30 11:41:03.453: W/System.err(8577): at android.widget.GridView.onMeasure(GridView.java:1030)
01-30 11:41:03.453: W/System.err(8577): at android.view.View.measure(View.java:15172)
01-30 11:41:03.453: W/System.err(8577): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
01-30 11:41:03.457: W/System.err(8577): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
01-30 11:41:03.457: W/System.err(8577): at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
01-30 11:41:03.457: W/System.err(8577): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
01-30 11:41:03.457: W/System.err(8577): at android.view.View.measure(View.java:15172)
01-30 11:41:03.457: W/System.err(8577): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
01-30 11:41:03.457: W/System.err(8577): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
01-30 11:41:03.457: W/System.err(8577): at android.view.View.measure(View.java:15172)
01-30 11:41:03.457: W/System.err(8577): at android.widget.LinearLayout.measureVertical(LinearLayout.java:833)
01-30 11:41:03.457: W/System.err(8577): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
01-30 11:41:03.461: W/System.err(8577): at android.view.View.measure(View.java:15172)
01-30 11:41:03.461: W/System.err(8577): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
01-30 11:41:03.461: W/System.err(8577): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
01-30 11:41:03.461: W/System.err(8577): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2148)
01-30 11:41:03.461: W/System.err(8577): at android.view.View.measure(View.java:15172)
01-30 11:41:03.461: W/System.err(8577): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1850)
01-30 11:41:03.464: W/System.err(8577): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1102)
01-30 11:41:03.464: W/System.err(8577): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1275)
01-30 11:41:03.464: W/System.err(8577): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
01-30 11:41:03.464: W/System.err(8577): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4214)
01-30 11:41:03.464: W/System.err(8577): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
01-30 11:41:03.464: W/System.err(8577): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
01-30 11:41:03.464: W/System.err(8577): at android.view.Choreographer.doFrame(Choreographer.java:525)
01-30 11:41:03.464: W/System.err(8577): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
01-30 11:41:03.464: W/System.err(8577): at android.os.Handler.handleCallback(Handler.java:615)
01-30 11:41:03.464: W/System.err(8577): at android.os.Handler.dispatchMessage(Handler.java:92)
01-30 11:41:03.464: W/System.err(8577): at android.os.Looper.loop(Looper.java:137)
01-30 11:41:03.468: W/System.err(8577): at android.app.ActivityThread.main(ActivityThread.java:4745)
01-30 11:41:03.468: W/System.err(8577): at java.lang.reflect.Method.invokeNative(Native Method)
01-30 11:41:03.468: W/System.err(8577): at java.lang.reflect.Method.invoke(Method.java:511)
01-30 11:41:03.468: W/System.err(8577): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-30 11:41:03.468: W/System.err(8577): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-30 11:41:03.468: W/System.err(8577): at dalvik.system.NativeStart.main(Native Method)
編集:これが私の新しいコードですが、まだ例外があります:
try {
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");
Date d = new Date();
d = sdf.parse(expire);
Log.i("ImageFetcher","d ="+d.getDay());
long timestamp = d.getTime();
return timestamp;
} catch (ParseException e) {
e.printStackTrace();
}