Friday, November 16, 2012

Convert date times based on TimeZone in XSL

Recently I had a requirement where I had to convert time to different timezones based on the clients different locations. One issue we had was with the table column length which was limited to 20 chars.So we had to format the time to remove the offset as it full timestamp usually has a lenght close to 30 chars.Since we were not able to insert the time directly, we had to come up with a workaround.

I am pasting the XSL code snippet  which can be used to modify the timestamp based on the offset which defines the timezone time difference.

<xsl:variable name="TIMEZONE_DIFF"
          <xsl:variable name="DIFF_SIGN"
          <xsl:variable name="DIFF_HOUR"
          <xsl:variable name="DIFF_MIN"
          <xsl:variable name="DURATION"

                  <xsl:when test="$DIFF_SIGN='+'">                
                      <xsl:value-of select='xp20:format-dateTime(xp20:add-dayTimeDuration-to-dateTime(startTime,$DURATION),"[M01]-[D01]-[Y0001] [H01]:[m01]:[s01]")'/>
                    </ns0: StartTime >
                    <ns0: StartTime >
                      <xsl:value-of select='xp20:format-dateTime(xp20:subtract-dayTimeDuration-from-dateTime(startTime,$DURATION),"[M01]-[D01]-[Y0001] [H01]:[m01]:[s01]")'/>
                    </ns0: StartTime >
Hope this helps

1 comment:

Anonymous said...

Your means of telling all in this post is truly pleasant, all be capable of effortlessly
understand it, Thanks a lot.

My blog :: Dungeon Hunter 4 Hack