我需要将当前日期时间转换为ios8601格式,例如:
日期和时间格式:01 Jan 2014 BST 12:00 PM
最终在我的jsp上,我希望将格式化的日期放入
<time datetime="{date and time in ISO8601}">{date and time in format: 01 Jan 2014 BST 12:00 PM}</time>
我当前的尝试:
TimeZone tz = TimeZone.getTimeZone("BST");
DateFormat df = new SimpleDateFormat("dd-MM-yyyy'T'HH:mm'Z'");
df.setTimeZone(tz);
String nowAsISO = df.format(new Date());
但结果看起来不像我期望得到的......
最佳答案
此模式将为您提供所需的内容:
SimpleDateFormat format = new SimpleDateFormat("dd MMM yyyy zzz HH:mm a");
format.setTimeZone(TimeZone.getTimeZone("Europe/London"));
System.out.println(format.format(new Date()));
打印:
英国夏令时 2014 年 9 月 1 日下午 15:37
注意:我假设您正在寻找 BST = 英国夏令时间,应如上所示表示。如果您需要孟加拉国时间,请使用 Asia/Dhaka
作为时区指示符。另请注意,英国夏令时间在 1 月 1 日无效(如您的示例中所引用)。
关于java - 将当前日期时间转换为 ISO 8601 格式的优雅方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25607733/