Get value of day month from Date object in Android?

import android.text.format.DateFormat; String dayOfTheWeek = (String) DateFormat.format(“EEEE”, date); // Thursday String day = (String) DateFormat.format(“dd”, date); // 20 String monthString = (String) DateFormat.format(“MMM”, date); // Jun String monthNumber = (String) DateFormat.format(“MM”, date); // 06 String year = (String) DateFormat.format(“yyyy”, date); // 2013

java.text.ParseException: Unparseable date

Your pattern does not correspond to the input string at all… It is not surprising that it does not work. This would probably work better: SimpleDateFormat sdf = new SimpleDateFormat(“EE MMM dd HH:mm:ss z yyyy”, Locale.ENGLISH); Then to print with your required format you need a second SimpleDateFormat: Date parsedDate = sdf.parse(date); SimpleDateFormat print = … Read more

How to parse dates in multiple formats using SimpleDateFormat

You’ll need to use a different SimpleDateFormat object for each different pattern. That said, you don’t need that many different ones, thanks to this: Number: For formatting, the number of pattern letters is the minimum number of digits, and shorter numbers are zero-padded to this amount. For parsing, the number of pattern letters is ignored … Read more

How to convert a String to a Date using SimpleDateFormat?

Try this: new SimpleDateFormat(“MM/dd/yyyy”) MM is “month” (not mm) dd is “day” (not DD) It’s all in the javadoc for SimpleDateFormat FYI, the reason your format is still a valid date format is that: mm is “minutes” DD is “day in year” Also, you don’t need the cast to Date… it already is a Date … Read more

How to parse month full form string using DateFormat in Java?

You are probably using a locale where the month names are not “January”, “February”, etc. but some other words in your local language. Try specifying the locale you wish to use, for example Locale.US: DateFormat fmt = new SimpleDateFormat(“MMMM dd, yyyy”, Locale.US); Date d = fmt.parse(“June 27, 2007”); Also, you have an extra space in … Read more

Displaying AM and PM in lower case after date formatting

This works public class Timeis { public static void main(String s[]) { long ts = 1022895271767L; SimpleDateFormat sdf = new SimpleDateFormat(” MMM d ‘at’ hh:mm a”); // CREATE DateFormatSymbols WITH ALL SYMBOLS FROM (DEFAULT) Locale DateFormatSymbols symbols = new DateFormatSymbols(Locale.getDefault()); // OVERRIDE SOME symbols WHILE RETAINING OTHERS symbols.setAmPmStrings(new String[] { “am”, “pm” }); sdf.setDateFormatSymbols(symbols); String … Read more

Java format yyyy-MM-dd’T’HH:mm:ss.SSSz to yyyy-mm-dd HH:mm:ss

SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd’T’HH:mm:ss”); SimpleDateFormat output = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”); Date d = sdf.parse(time); String formattedTime = output.format(d); This works. You have to use two SimpleDateFormats, one for input and one for output, but it will give you just what you are wanting.

Using Alphabetic Characters in SimpleDateFormat Pattern String

Surrounding the T with single quotes should work: yyyy-MM-dd’T’hh:mm:ssZ Quoting from the documentation (emphasis mine): Date and time formats are specified by date and time pattern strings. Within date and time pattern strings, unquoted letters from ‘A’ to ‘Z’ and from ‘a’ to ‘z’ are interpreted as pattern letters representing the components of a date … Read more