我遇到了问题而且我不知道自己做错了什么。
我正在尝试转换此字符串"星期五,2016年1月29日10:29:54 + 0100"到DateTime对象。
我为这种类型的日期设置了这种模式:" EEE,d MMM yyyy HH:mm:ss Z"
申请仍在让我java.lang.IllegalArgumentException()
,我不知道为什么......
功能正在成功:
public static String getTimeFromPublicDate(String date) {
DateTimeFormatter formatter = DateTimeFormat.forPattern("EEE, dd MMM yyyy HH:mm:ss Z");
try {
DateTime dateTime = DateTime.parse(date, formatter);
return dateTime.getDayOfMonth()
+"/"+ dateTime.getMonthOfYear()+"/"+ dateTime.getYear();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
stackTrace:
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at org.joda.time.format.DateTimeFormatter.parseDateTime(DateTimeFormatter.java:945)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at org.joda.time.DateTime.parse(DateTime.java:160)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at pl.antyradio20.model.NewsData.getTimeFromPublicDate(NewsData.java:63)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at pl.antyradio20.view.adapter.newsAdapter.twoImages.TwoImagesAdapter.onBindViewHolder(TwoImagesAdapter.java:72)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at pl.antyradio20.view.adapter.newsAdapter.twoImages.TwoImagesAdapter.onBindViewHolder(TwoImagesAdapter.java:18)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at android.support.v7.widget.RecyclerView$Adapter.onBindViewHolder(RecyclerView.java:5217)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at android.support.v7.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:5250)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4487)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4363)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1961)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1370)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1333)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at android.support.v7.widget.LinearLayoutManager.scrollBy(LinearLayoutManager.java:1161)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at android.support.v7.widget.LinearLayoutManager.scrollVerticallyBy(LinearLayoutManager.java:1018)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at android.support.v7.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:3807)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at android.view.Choreographer.doCallbacks(Choreographer.java:580)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at android.view.Choreographer.doFrame(Choreographer.java:549)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at android.os.Handler.handleCallback(Handler.java:739)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at android.os.Looper.loop(Looper.java:135)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5376)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at java.lang.reflect.Method.invoke(Native Method)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at java.lang.reflect.Method.invoke(Method.java:372)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
01-29 15:32:25.739 30825-30825/pl.antyradio20 W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)