I am trying to convert a String DateTime
value which is present in a flat file as a Date
object after parsing the flat file in my code.
I have
Can you please let me know whats the issue here.
Sure. You're effectively calling date.toString()
, which doesn't know anything about the SimpleDateFormat
which was used to parse the original text value. A Date
is just an instant in time. It has no notion of a per-instance format. Additionally, it doesn't know about a time zone. You've given a value in PDT, which was then parsed... and when you print it, it's using the system local time zone (IST). That's what Date.toString
always does.
If you want to format a Date
in a particular way, using a particular format in a particular time zone, call DateFormat.format
.