dateformat « SimpleDateFormat « Java Data Type Q&A

1. Java Date Format that allows - / or . as separators within date

What's the nicest way to parse a date that can be in one of the following formats

 "dd-MM-yyyy HH:mm"
 "dd/MM/yyyy HH:mm"
 "dd.MM.yyyy HH:mm"
without creating 3 SimpleDateFormats and parsing against each ...

2. Java DateFormat and SimpleDateFormat returning a date that is incorrect

Today is Tuesday, February 9, 2010 and when I print the date I get the wrong date:

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

Date today = formatter.parse(String.format("%04d-%02d-%02d",

3. SimpleDateFormat give inconsistent results

I am trying to parse a date and I am getting different results when I run the code locally/BST compare to a server in Paris/CEST. I've reproduced the issue in a ...

4. Is this a Java DateFormat bug?

The pattern is "dd-MM-yyyy" I think the string "01-01-2010mwwwwwwwwwwwwwww" does not satisfy the pattern, but the following code shows the contrary. Anyone can explain why?

public static void main(String[] args) throws Exception {


5. SimpleDateFormat format wrong values

The following code:

SimpleDateFormat sdf = new SimpleDateFormat("MM/dd");
System.out.println(sdf.format(new Date(1293253200))); // 12/25/2010 05:00 GMT
System.out.println(sdf.format(new Date(1293339600))); // 12/26/2010 05:00 GMT
System.out.println(sdf.format(new Date(1293426000))); // 12/27/2010 05:00 GMT
Using a default DateFormat via SimpleDateFormat.getDateInstance(); prints these dates as ...

6. Why Does Java's SimpleDateFormat parse this

Hi I've got a simple date format set up with a custom format string: MMddyy and I give it the following value to parse: 4 1 01 I don't think it should parse this because ...

7. Java SimpleDateFormat parse issue into WEKA

I swear I'm using the correct date format but I keep getting a parse error when loading into WEKA.

Here is an example dataset:
@RELATION example

@ATTRIBUTE timestamp DATE "EEEMMMddhh:mm:ssZ"

8. Parse short US date into yyyy-MM-dd, java

I want to parse the date "3/27/11" which I think is equal to US short date.

DateFormat df1 = new SimpleDateFormat("MM/dd/yy");
DateFormat df2 = new SimpleDateFormat("yyyy-MM-dd");
Date date = (Date) df1.parseObject("03/27/11");
System.out.println("New date: " + ...

9. String to Date; Format of input varies

For the project I'm working on at the moment I need to convert a String to a Date. Unfortunately the date and time aren't formatted the same in all the Strings ...

10. Creating a custom week counter in Java?

I am trying to create a custom week counter but am having quite a lot of trouble and feel like I am going about it all wrong. The method should ...

11. Date format error with "2011-07-27T06:41:11+00:00"

I'm trying to format a time/date string:

String date = "2011-07-27T06:41:11+00:00";
DateFormat formatter = new SimpleDateFormat("yyyy MM-dd'T'HH:mm:ssz"); //2011-07-27T06:41:11+00:00
Date Sdate = formatter.parse(date.toString());
This is throwing the error
unable to parse newDate.
I don't understand why I'm getting ...

12. DateFormat is printing new Date(0) as epoch + 1 hour

The following test fails:

DateFormat df = new SimpleDateFormat("HH:mm:ss z");
assertEquals("00:00:00 GMT", df.format(new Date(0)));
expected "00:00:00 GMT" but was "01:00:00 GMT" Could someone point out where I'm being stupid please? I've spent longer looking at this ...

13. Java TimeZone conversions

I understand that java Date is timezoneless and trying to set different timezone on Java Calendar wouldn't convert date to an appropriate Time Zone. So I have tried following code

 public ...