I want to format the date/time that I got from metadata calling of Dropbox API. I have read the detail about formatting the date/time from it reference: Dropbox API Date format but still not clear about that. I use JAVA and retrieve the metadata via JSON. What I need to do is
Format: Thu, 27 Sep 2012 13:44:09 +0000 ----to---> 27/09/2012 13:44:09
I have try SimpleDateFormat but it was returned me something like unable to convert string to datetime format. Thank you in advance.
Try this:
SimpleDateFormat df = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z", Locale.US);
Date date = df.parse("Thu, 27 Sep 2012 13:44:09 +0000");
System.out.println(date);
When you want to convert date string into Date
object, you can use SimpleDateFormat
. While creating the object, specify the format code, then parse the string with parse()
method of SimpleDateFormat
. Other type can also be parsed if you specify proper format code.
Be sure to set the locale when you instantiate SimpleDateFormat
. It works well without locale if your VM default locale is US. Otherwise like CJK, you must specify the locale to prevent parsing error.
For more detail, refer to the following URL: http://docs.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html
Should be something like this:
(Exception handling ommited)
//Thu, 27 Sep 2012 13:44:09 +0000
SimpleDateFormat dfDb = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");
Date dateDb = dfDb.parse(yourStringDateFromDb);
//27/09/2012 13:44:09
SimpleDateFormat toYours = new SimpleDateFormat("dd/mm/yyyy HH:mm:ss");
String yourString = toYours.format(dateDb);
See: java.text.SimpleDateFormat
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With