0

Why code

Date time1 = new SimpleDateFormat("HH:mm", Locale.US).getCalendar().getTime();

return wrong year?

Mon Dec 12 08:49:57 GMT+03:00 1938

Why is 1938?

  • 2
    It's not a duplicate of the link provided by you, his question is "WHY" is it returning the wrong year, not "how to?" – Daksh Gargas Dec 12 '18 at 05:57

1 Answers1

-3

Because SimpleDateFormat("HH:mm", Locale.US).getCalendar() has something to do with Serialization which causes the problem

Check this answer

Use

Date currentTime = Calendar.getInstance().getTime();
Daksh Gargas
  • 3,498
  • 2
  • 23
  • 37
  • 1
    instead of answering a question that is a duplicate with an answer from the duplicated question, you should just mark the question as duplicate, and not copy (partially in your question) the other answer – Vladyslav Matviienko Dec 12 '18 at 06:25
  • Makes sense! I'll keep that in my mind. Thanks! – Daksh Gargas Dec 12 '18 at 06:34
  • @VladyslavMatviienko But again, defining "possible duplicates" doesn't really solve his problem. I wonder why people downvoted my answer, lol! – Daksh Gargas Dec 12 '18 at 06:48
  • “Has something to do with serialization” doesn’t really answer the question either. If you believe that a separate answer to this question is warranted, I think you should at least give a full answer. Link-only answers are discouraged (which I hope you have heard before). – Ole V.V. Dec 12 '18 at 06:59
  • I totally agree with you, but copying and pasting the whole explanation is kinda redundant, what he was actually looking for a solution. I'm not saying that I'm correct, but if my answer solved his problem, why bother downvoting it? :/ – Daksh Gargas Dec 12 '18 at 07:09
  • But yes, I support you point and I won't repeat it again :) – Daksh Gargas Dec 12 '18 at 07:10
  • 2
    Since you ask and since answers are just as much for future readers as for the asker, I do see the point in downvoting (and even flagging for deletion) incomplete answers (I haven’t downvoted, and no one has flagged). – Ole V.V. Dec 12 '18 at 07:44