本文介绍了android java从字符串解析日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  SimpleDateFormat dateFormatDateAndTime = new SimpleDateFormat(ddMMyyyyHHMM); 
Date startDateTime = dateFormatDateAndTime.parse(060420150134);
Log.v(TAG,startDateTime:+ startDateTime); // Fri Oct 06 01:00:00 GMT + 05:30 2017

所以,我必须解析 060420150134 ,以便我获得 06 Apr 2015 01:34 ,因为我的格式是 ddMMyyyyHHMM



但我得到这里 Fri Oct 06 01:00:00 GMT + 05:30 2017



所以我做错了什么?如何解析这里?

解决方案

您需要将第二个MM(月)更改为mm(分钟):

  SimpleDateFormat DateFormatDateAndTime = new SimpleDateFormat(ddMMyyyyHHmm); 


In android application I'm trying to parse Date from string to find difference between two times.

SimpleDateFormat dateFormatDateAndTime = new SimpleDateFormat("ddMMyyyyHHMM");
Date startDateTime = dateFormatDateAndTime.parse("060420150134");
Log.v(TAG, "startDateTime: " + startDateTime);  //Fri Oct 06 01:00:00 GMT+05:30 2017

So, I have to parse 060420150134 so that I get 06 Apr 2015 01:34 and for that my format is ddMMyyyyHHMM

But I get here Fri Oct 06 01:00:00 GMT+05:30 2017

So i'm doing what's wrong? How to parse here?

解决方案

You need to change the second MM (months) to mm (minutes):

SimpleDateFormat dateFormatDateAndTime = new SimpleDateFormat("ddMMyyyyHHmm");

这篇关于android java从字符串解析日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 23:19