All Questions

150
votes
5answers
301420 views

How to parse a date?

I am trying to parse this date with SimpleDateFormat and it is not working: import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Formaterclass { ...
110
votes
14answers
105571 views

How do you format the day of the month to say "11th", "21st" or "23rd" (ordinal indicator)?

I know this will give me the day of the month as a number (11, 21, 23): SimpleDateFormat formatDayOfMonth = new SimpleDateFormat("d"); But how do you format the day of the month to include an ordin...
53
votes
4answers
14998 views

Y returns 2012 while y returns 2011 in SimpleDateFormat

I wonder why 'Y' returns 2012 while 'y' returns 2011 in SimpleDateFormat: System.out.println(new SimpleDateFormat("Y").format(new Date())); // prints 2012 System.out.println(new SimpleDateFormat("y")...
170
votes
9answers
104656 views

Why is Java's SimpleDateFormat not thread-safe?

Please tell with a code example why is SimpleDateFormat not threadsafe. What is the problem in this class? Is The problem with format function of SimpleDateFormat? Please give a code which demonstra...
33
votes
8answers
53788 views

How to parse dates in multiple formats using SimpleDateFormat

I am trying to parse some dates that are coming out of a document. It would appear users have entered these dates in a similar but not exact format. here are the formats: 9/09 9/2009 09/2009 9/1/200...
61
votes
12answers
88165 views

simpledateformat parsing date with 'Z' literal

I am trying to parse a date that looks like this: 2010-04-05T17:16:00Z This is a valid date per http://www.ietf.org/rfc/rfc3339.txt. The 'Z' literal "imply that UTC is the preferred reference po...
123
votes
2answers
75717 views

Illegal pattern character 'T' when parsing a date string to java.util.Date

I have a date string and I want to parse it to normal date use the java Date API,the following is my code: public static void main(String[] args) { String date="2010-10-02T12:23:23Z"; String ...
13
votes
2answers
10250 views

Java - Unparseable date

I am trying to parse a date, but I am oddly getting an exception. This is the code: import java.util.Date; String strDate = "Wed, 09 Feb 2011 12:34:27"; Date date; SimpleDateFormat FORMATTER = ne...
125
votes
8answers
235602 views

Convert String to Calendar Object in Java

I am new to Java, usually work with PHP. I am trying to convert this string: Mon Mar 14 16:02:37 GMT 2011 Into a Calendar Object so that I can easily pull the Year and Month like this: String ...
52
votes
7answers
256472 views

How to convert a String to a Date using SimpleDateFormat?

I have this code snippet: DateFormat formatter1; formatter1 = new SimpleDateFormat("mm/DD/yyyy"); System.out.println((Date)formatter1.parse("08/16/2011")); When I run this, I get this as the output...

Previous Next