Android 要将日期从格式转换为“;dd-mmm-yyyy“;至;yyyy-mm-dd";。这是我的密码
我想将日期从格式“dd-mmm-yyyy”转换为“yyy-mm-dd”。这是我的密码Android 要将日期从格式转换为“;dd-mmm-yyyy“;至;yyyy-mm-dd";。这是我的密码,android,calendar,date-format,Android,Calendar,Date Format,我想将日期从格式“dd-mmm-yyyy”转换为“yyy-mm-dd”。这是我的密码 public void convertDate(){ GregorianCalendar todaysDate = (GregorianCalendar) month.clone(); // Its show the error over here. SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy", Locale.US);
public void convertDate(){
GregorianCalendar todaysDate = (GregorianCalendar) month.clone(); // Its show the error over here.
SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy", Locale.US);
currentdatestring = df.format(todaysDate.getTime());
try{
Date tdate3= df.parse(currentdatestring);
tdate4=targetDateformat.format(tdate3);
}
catch (ParseException e) {
Log.e(getPackageName(), e.getMessage());
e.printStackTrace();
}
但问题是它显示了一个空指针异常。我无法理解这个错误。如果有人能帮忙,请试试这个
DateFormat dffrom = new SimpleDateFormat("M/dd/yyyy");
DateFormat dfto = new SimpleDateFormat("yyyy-MM-dd");
Date today = dffrom.parse("7/1/2011");String s = dfto.format(today);
试试这个:
Date cDate = new Date();
DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = dateFormat.parse(cDate);
希望它能帮助你 如果
month.clone()
导致了NPE,则会出现month==null
。month
在何时何地获得赋值?是的,这是唯一的问题。谢谢你,伙计。其中一个解决方案被(-)分割