1

All

When I define a date object it automatically assumes it's MM/dd/YYYY, however I enter it as dd/MM/yyyy.

Date d1 = new Date("5/12/2015 10:30:00");

When I get the name of the day from that date it gives me the name of May 12 (Tuesday) instead of the name of december 5 (Saturday).

dateName = new SimpleDateFormat("EEEE", Locale.ENGLISH).format(d1);

Can anyone help me out?

Tjekkles
  • 5,352
  • 8
  • 36
  • 53
  • 1
    Kindly refer [this](http://stackoverflow.com/a/6789565/1728206). – janani Jan 08 '16 at 08:49
  • @Tjekkles Be careful about confusing `YYYY` with `yyyy` as in your first sentence. They have different meanings as coded parsing patterns. – Basil Bourque Jan 09 '16 at 23:56
  • And a dup of [this](http://stackoverflow.com/q/5270272/642706), [this](http://stackoverflow.com/q/18333099/642706) and many more. – Basil Bourque Jan 10 '16 at 00:00

1 Answers1

3

You can use a SimpleDateFormat formatter for that.

SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
Date newDate = format.parse("05/12/2015");

With that you can define your own format-strings!

ParkerHalo
  • 4,341
  • 9
  • 29
  • 51
  • One question: when I add a time to it (hh:mm:ss) it assumes its AM/PM, but I want 12:00:05 to be noon, not convert it to 00:00:05, how can I prevent this? – Tjekkles Jan 08 '16 at 12:11