Java简单日期格式英国时间 [英] Java simple date format british time
本文介绍了Java简单日期格式英国时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用简单的日期格式,允许用户指定他们发送数据的时区:
I am using simple date format to allow users to specify which time zone they are sending data in:
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,z");
这工作正常:
例如
This works fine: e.g.
df.parse("2009-05-16 11:07:41,GMT");
但是,如果有人总是在伦敦时间发送时间(即考虑到夏令时),什么会是approniate时区字符串要添加吗?
例如这不工作:
However, if someone is always sending time in London time (i.e. taking into account daylight savings), what would be the approriate time zone String to add? e.g. this doesnt work:
df.parse("2009-05-16 11:07:41,Western European Time");
System.out.println(date);
Sat May 16 12:07:41 BST 2009
我想匹配时间
谢谢。
推荐答案
夏令时,它是 BST
。在今年的其余时间里,它是 GMT
。
In daylight saving time, it's BST
. In the rest of the year it's GMT
.
我建议你使用通用名称(整年) ),这是欧洲/伦敦
。你可以使用这样的东西:
I suggest that you use the generic name (for the whole year), which is Europe/London
. You can use something like this:
String userInput = "2009-05-16 11:07:41,Europe/London";
String[] tokens = userInput.split(",");
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
df.setTimeZone(TimeZone.getTimeZone(tokens[1]));
System.out.println(df.parse(tokens[0]));
这种情况下的输出是:
Sat May 16 11:07:41 GMT+01:00 2009
这篇关于Java简单日期格式英国时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文