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
How to Represent a Range in Java
Do Not Use System.Out.Println in Server Side Code
How to Get the Parent Base Class Object Super.Getclass()
Deserialize Java 8 Localdatetime with Jacksonmapper
How to Implement Task Prioritization Using an Executorservice in Java 5
How to Check the Type of a Value from a JSONobject
Does Java Guarantee That Object.Getclass() == Object.Getclass()
Main Method Not Found Even If I'Ve Declared It
Netbeans - Error: Could Not Find or Load Main Class
Value Change Listener for Javafx's Textfield
How to Convert a Java Object to Xml with Open Source APIs
Dynamic Generic Typing in Java
Why Can't I Use \U000D and \U000A as Cr and Lf in Java
Efficiently Finding the Intersection of a Variable Number of Sets of Strings
Favor Composition Over Inheritance
Are Two Java Objects with Same Hashcodes Not Necessarily Equal