Ad

BST Time Is Wrong

With the below code, every timezone is printing the value correctly except BST

​import java.text.*;

def format = "yyyy-MM-dd HH:mm:ssXXX"
def dt = new Date();
println dt;

SimpleDateFormat utcFormat = new SimpleDateFormat(format)
utcFormat.setTimeZone(TimeZone.getTimeZone("UTC"))
println utcFormat.format(dt)

SimpleDateFormat istFormat = new SimpleDateFormat(format)
istFormat .setTimeZone(TimeZone.getTimeZone("IST"))
println istFormat.format(dt)

SimpleDateFormat cetFormat = new SimpleDateFormat(format)
cetFormat.setTimeZone(TimeZone.getTimeZone("CET"))
println cetFormat.format(dt)

SimpleDateFormat bstFormat = new SimpleDateFormat(format)
bstFormat.setTimeZone(TimeZone.getTimeZone("BST"))
println bstFormat.format(dt)

Output:

Mon Mar 26 09:04:14 UTC 2018

2018-03-26 09:04:14Z

2018-03-26 14:34:14+05:30

2018-03-26 11:04:14+02:00

2018-03-26 15:04:14+06:00

Here BST time is wrong. Whats wrong with it?

Ad

Answer

It seems you expect BST to be British Summer Time, but in this case it represents Bangladesh Standard Time. Also see What does Java's BST ZoneId represent?

From Answer:

the below code works

SimpleDateFormat bstFormat = new SimpleDateFormat(format)
bstFormat.setTimeZone(TimeZone.getTimeZone("Europe/London"))
println bstFormat.format(dt)
Ad
source: stackoverflow.com
Ad