java XSL使用偏移量比较将UTC时间转换为本地日期时间
我们接收与UTC时间相关的datetime元素,如2004-04-12T13:20:00Z
我们希望在本地datetime中输出datetime,即用相对于UTC时间的偏移量表示,如2004-04-12T12:20:00-01:00
有人能在XSLT中帮助实现这一点吗
或者是否存在实现此目的的功能模板
你可以在下面搜索框中键入要查询的问题!
我们接收与UTC时间相关的datetime元素,如2004-04-12T13:20:00Z
我们希望在本地datetime中输出datetime,即用相对于UTC时间的偏移量表示,如2004-04-12T12:20:00-01:00
有人能在XSLT中帮助实现这一点吗
或者是否存在实现此目的的功能模板
# 1 楼答案
假设您正在使用Oracle SOA套件进行转换
这会解决你的问题
# 2 楼答案
假设有这样一个XML测试文件
类似这样的XSLT-2.0文件将时区设置为
-1
:其产出是:
# 3 楼答案
要将给定的dateTime值转换为当前本地时区,请使用
adjust-dateTime-to-timezone()
函数,而不指定timezone
参数例如:
将返回:
如果在转换时,系统的本地时间与UTC的偏移量为-1小时
重要:
如果您的本地时间与UTC的偏移不是恒定的,而是由于夏令时而发生变化,则这可能不会产生预期的结果。要正确地将2004年4月的日期转换为当时的当地时间,您需要知道该特定时间点的UTC偏移量。XSLT没有这种功能,您必须在另一个可以访问Olson database的应用程序中进行转换
增加:
所有这些都需要XSLT2.0。既然您现在已经澄清了,那么您实际上是在使用XSLT 1.0:
以下是将UTC转换为UTC-1:00(作为常量)的模板示例:
演示:http://xsltransform.net/bFWR5F8