|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Barefoot on the Moon!
Staff
Premium Member
Join Date: Aug 2002
Location: Northeastern USA
Posts: 13,385
|
Convert String to Calendar in Java
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): 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: Code:
Calendar startthis = timeFormatStored.format(date1).getDate(); And also: Code:
Calendar startthis = timeFormatStored.parse(temp); 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?
__________________
There are two secrets to staying young, being happy, and achieving success. You have to laugh and find humor every day, and you have to have a dream.
|
|
|
|
|
|
#2 |
|
Barefoot on the Moon!
Staff
Premium Member
Join Date: Aug 2002
Location: Northeastern USA
Posts: 13,385
|
Nevermind, I *finally* was able to find someone who could answer this question.
|
|
|
|
|
|
#3 |
|
Member (7 bit)
|
just out of curiosity, what was the solution?
|
|
|
|
|
|
#4 |
|
Barefoot on the Moon!
Staff
Premium Member
Join Date: Aug 2002
Location: Northeastern USA
Posts: 13,385
|
Sorry, thought I posted it.
Here it is: PHP Code:
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|