If i have:
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateStr = dateFormat.format(new Date());
The output will be: 2014-09-30 14:19:17 when my local time is 2014-09-30 16:19:17
I need to get Date type in specific timezone and not String Type!
My question is , how can i get new Date() on "Europe/London" timezone,
My question is, how can i get
new Date()on "Europe/London" timezone
You can't. The
java.util.Date class represents an instant in time. It is not aligned to any local time zone.
Internally, it tracks the number of milliseconds since Midnight, January 1st, 1970 UTC. A local time zone might be applied when you use it, but there is no time zone setting contained within the
Date class itself.
Use Calendar , for example :
TimeZone timeZone= TimeZone.getTimeZone("Europe/London")); Calendar cal = Calendar.getInstance(timeZone);
also , the good thing about dates is that they arent dependant of TimeZone , its just time in millis since epoch (some time a while back) . The way you are using it now is actually the right solution .