How to get the current time in your time zone in Java
I don’t know why Java is almost impossible to do such a simple thing. I’ve tried a lot of solutions I’ve found online, but there doesn’t seem to be a simple, clean and effective solution.
Here is my recent solution attempt
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("America/Los_Angeles")); System.out.println( sdf.format(calendar.getTime()) );
My exception output: 27/
My real output: 03/
What’s the point of that.
Set the time zone in the
SimpleDateFormat instance instead