How do you convert a String in yyyyMMddHHmmss format to a Calendar value so it can be edited?
I've been looking at the SimpleDateFormat, the Calendar and the Date APIs and haven't been able to figure out how to do it
What is the format I use for formatting the String to whatever it is that Calendar can read?
So, I have temp, which grabs the attribute data from an XML file, and I'm trying to convert it to a Date so it can be converted into a Calendar (I'm not sure if this is the correct approach):
However, I get an error when I try this saything that I cannot convert from int to Calendar.Code:SimpleDateFormat inputFormat = new SimpleDateFormat("yyyyMMddHHmmss"); SimpleDateFormat timeFormatStored = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String temp = frontSplitString((attr.getValue(i).toString()).trim()); java.util.Date date1 = null; try { date1 = inputFormat.parse(temp); } catch (ParseException e) { e.printStackTrace(); } Calendar startthis = date1.getDate();
I've also tried:
But I get this error: The method getDate() is undefined for the type String MyHandler.javaCode:Calendar startthis = timeFormatStored.format(date1).getDate();
And also:
Error: Cannot cast from Date to Calendar MyHandler.javaCode:Calendar startthis = timeFormatStored.parse(temp);
That doesn't work either.Code:Calendar startthis = Timestamp.valueOf(temp);
Error: Type mismatch: cannot convert from Timestamp to Calendar MyHandler.java
Where does the problem lay? Or, what am I missing? What is the code that makes it work?


Reply With Quote



Bookmarks