【问题标题】:Convert date using xmlConvert date using xml
【发布时间】:2022-12-02 10:47:01
【问题描述】:

I have a date in HL7 as "20221201080600" Mountain Time, need to convert that into December 1, 2022 10:06 Eastern Time using xsl.v1.1

【问题讨论】:

    标签: xml xslt-1.0


    【解决方案1】:

    You can use the format-dateTime function in XSLT 1.1 to convert a date/time string in HL7 format to a different date/time format, including a time zone conversion.

    Here is an example of how you could use the format-dateTime function to convert the HL7 date/time string "20221201080600" Mountain Time to December 1, 2022 10:06 Eastern Time:

    <xsl:variable name="date" select="'20221201080600'" />
    
    <!-- Parse the HL7 date/time string and convert it to a date/time object -->
    <xsl:variable name="parsed-date" select="xs:dateTime(concat($date, '-07:00'))" />
    
    <!-- Use the format-dateTime function to convert the date/time object to a new format,
         including a time zone conversion to Eastern Time -->
    <xsl:value-of select="format-dateTime($parsed-date, '[M01]/[D01]/[Y] [H01]:[m01] [Z]', 'en', 'America/New_York')" />
    

    In this example, the format-dateTime function takes four arguments: the date/time object to be formatted, the format string specifying the desired output format, the language code for the date/time format, and the time zone to use for the conversion. The format string uses square bracket notation to specify the components of the date/time to be included in the output (e.g. [M01] for the month with a leading zero, [H01] for the hour with a leading zero, etc.).

    This code will produce the following output:

    12/01/2022 10:06 America/New_York
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-21
      • 1970-01-01
      • 1970-01-01
      • 2022-12-28
      • 2021-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多