I have an XML document that returns the following value for a date-time stamp:
Wed, 18 Feb 2015 22:38:00 +0000
How can I change this (using Java), so I can get this:
Wednesday, February 18, 2015
I have an XML document that returns the following value for a date-time stamp:
Wed, 18 Feb 2015 22:38:00 +0000
How can I change this (using Java), so I can get this:
Wednesday, February 18, 2015
Have you this date as a string in java?
Try this:
String stringdate = "Wed, 18 Feb 2015 22:38:00 +0000";
//Convert from string to date
DateFormat stringformat = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.ENGLISH);
Date date = stringformat.parse(stringdate);
//Convert from date to string
DateFormat newformat = new SimpleDateFormat("EEEE, MMMM d, yyyy ", Locale.ENGLISH);
System.out.println(newformat.format(date));
With timestamp:
Timestamp d = new Timestamp(System.currentTimeMillis());
//Convert from date to string
DateFormat newformat = new SimpleDateFormat("EEEE, MMMM d, yyyy ", Locale.ENGLISH);
System.out.println(newformat.format(d));
In Java, using SimpleDateFormat, the following should convert the date in the way required by your example.
import java.text.*;
import java.util.*;
public class HelloWorld{
public static void main(String []args) throws ParseException {
String input = "Wed, 18 Feb 2015 22:38:00 +0000";
SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
Date date = sdf.parse(input);
SimpleDateFormat format = new SimpleDateFormat("EEEE, MMMM d, yyyy");
String dateString = format.format(date);
System.out.println(dateString);
}
}