How to get the pattern of the given date object
I am getting one Date object as a parameter in my method and I want to know the pattern of the date to convert it into user selected timezone.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’ve misunderstood what a
Datemeans. It’s just a number of milliseconds since the Unix epoch. It has no concept of time zone, calendar or text format. If it helps, think of it as being a bit likeint– anintisn’t in hex, decimal or binary – it’s just a number within a certain range. If you parse “1a” as hex, that gives an indistinguishable result from parsing “26” as decimal. The same goes forDate.Of course, this was already explained in comments to some extent, but your reply of:
… suggests you didn’t really understood it. The concept of “which already set a format” makes no sense in the context of a
Date.If you need a particular format to be applied, you should pass the
DateFormatalong as well as theDate.