I have written following code. I want to get Date object in UTC format.
I am able to get expected date string in UTC using SimpleDateFormat
. But using
A Date doesn't have any time zone. What you're seeing is only the formatting of the date by the Date.toString()
method, which uses your local timezone, always, to transform the timezone-agnostic date into a String that you can understand.
If you want to display the timezone-agnostic date as a string using the UTC timezone, then use a SimpleDateFormat with the UTC timezone (as you're already doing in your question).
In other terms, the timezone is not a property of the date. It's a property of the format used to transform the date into a string.