Click here to Skip to main content
15,941,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi to everyone
I'm developing an Android application and I have to parse a date like Fri Oct 07 23:30:00 CEST 2011 and format into a string like Lun 07 Ott 2011 (in italian).
I tried with this:
Java
final DateFormat PARSING_PATTERN = new SimpleDateFormat("E MMM dd kk:mm:ss z yyyy", Locale.US);
final DateFormat FORMATTING_PATTERN = new SimpleDateFormat("E dd MMM yyyy");
String outputDate;
String inputDate= ..........;   //La data nel formato suddetto
try {
       Date date = PARSING_PATTERN.parse(inputDate);
       outputDate = FORMATTING_PATTERN.format(date);
} catch (ParseException e) {
       outputDate = "";
}

but it throws a ParseException. If I run the same code in a Java project, there's no problem...
Someone can help me?
Thanks
Posted

Hi,
try this method...


Java
string inputDate=........;
try {
Simple DateFormat FORMATTING_PATTERN= new SimpleDateFormat("YYYY/MM/DD");
Parse Position.Position= new ParsePosition(0);
Date stringToDate = FORMATTING_PATTERN.Parse(inputDate, Position);
}

catch { }




Hope it will help you....
 
Share this answer
 
v3
Hi,
I solved with this
Java
final DateFormat PARSING_PATTERN = new SimpleDateFormat("E MMM dd kk:mm:ss Z yyyy");
final DateFormat FORMATTING_PATTERN= new SimpleDateFormat("E dd MMMM yyyy", Locale.ITALIAN);
String inputDate = .....;
inputDate.replace("CEST", "+00:00");
String outputDate="";
try {
	Date d= PARSING_PATTERN.parse(data);
	outputDate= FORMATTING_PATTERN.format(d).toString();
} 
catch (ParseException e) {...}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900