How to Convert "Mon Jun 18 00:00:00 Ist 2012" to 18/06/2012

How to convert Mon Jun 18 00:00:00 IST 2012 to 18/06/2012?

I hope following program will solve your problem

String dateStr = "Mon Jun 18 00:00:00 IST 2012";
DateFormat formatter = new SimpleDateFormat("E MMM dd HH:mm:ss Z yyyy");
Date date = (Date)formatter.parse(dateStr);
System.out.println(date);

Calendar cal = Calendar.getInstance();
cal.setTime(date);
String formatedDate = cal.get(Calendar.DATE) + "/" + (cal.get(Calendar.MONTH) + 1) + "/" + cal.get(Calendar.YEAR);
System.out.println("formatedDate : " + formatedDate);

Convert string to date with IST

Try changing format to "EEE MMM dd HH:mm:ss yyyy" and set IST timeZone

changedDate = changedDate.replace("IST ", "");
SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyy");
TimeZone timeZone=TimeZone.getTimeZone("IST");
formatter.setTimeZone(timeZone);

Date date = (Date)formatter.parse(changedDate);

how to convert Tuesday , December 25th, 1900 into MM/dd/yyyy format in java

The issue is that your input string does not match your input format. I changed the format and it is working fine. Try,

String caseDate = "Tuesday , December 25th, 1900";
SimpleDateFormat inputFormat = new SimpleDateFormat("EEEE , MMMM dd'th', yyyy");
Date date = inputFormat.parse(caseDate);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String formattedDate = formatter.format(date);
System.out.println(formattedDate);

Convert timestamp to simple date in Java and add to ParseObject

We can always convert the date to string in the needed format and add to requestObject

Sample Updated

for (ParseObject requestObject: requestsArrayList) {
SimpleDateFormat sdf2 = new SimpleDateFormat("E MMM dd");
String date = null;
try {
date = sdf.format(requestObject.getDate(ParseConstantsUtil.REQUEST_DATE_REQUESTED));
log.info(String.valueOf(date));
} catch (java.text.ParseException e1) {
e1.printStackTrace();
}
requestObject.add(ParseConstantsUtil.REQUEST_DATE_REQUESTED, date);
}

How to convert 2012-03-04 00:00:00.0 to Date with Format dd-mm-yyyy HH:mm:ss Using Java

The process of converting date strings is rather straightforward. You define the input format, use it to parse the original string, then define the output format, and use that to convert it back to a string.

I have the impression that you are trying to shortcut this, by reusing the same format for parsing and output? Use two formats, then!

// Convert input string into a date
DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");
Date date = inputFormat.parse(inputString);

// Format date into output format
DateFormat outputFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
String outputString = outputFormat.format(date);


Related Topics



Leave a reply



Submit