Here I found some problem to maintain one simple date response to get 12 hours and 24 hours. Both time are different in one date format.
Code which I have used currently:
My Date String Response = “2011-12-12T19:41:15.17Z”
Code
private static final SimpleDateFormat dateFormatToolTipResponse = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
private SimpleDateFormat cunsultationPostTimezone12 = new SimpleDateFormat("MM/dd/yy hh:mm a z");
private SimpleDateFormat cunsultationPostTimezone24 = new SimpleDateFormat("MM/dd/yy HH:MM z");
public String formateDateTimeConsultation(String dateTime)
{
StringBuffer strResult = new StringBuffer();
strResult.append(getPostTimecunsultation(parseDate(dateTime)));
return strResult.toString();
}
private static Date parseDate(String date)
{
try {
return dateFormatToolTipResponse.parse(date);
} catch ( Exception e ){
return null;
}
}
private String getPostTimecunsultation(Date date)
{
if(date != null){
if(ConstantCodes.is24Hours)
{
return cunsultationPostTimezone24.format(date);
}
else
{
return cunsultationPostTimezone12.format(date);
}
}
return "";
}
========================================
Here is my output
24 hours = 12/12/11 11:12 PST
12 hours = 12/12/11 11:42 AM PST
I couldn’t find what’s wrong in this.
Please can you suggest some ideas?
you set the MM in the time in 24 format
so you always getting Month value Caps M will give you the Month value while small m for minute change with this below line and then try