Jump to content

convert date to GMT


Guest AKhugsal

Recommended Posts

Guest AKhugsal

I have date comming in this format in a xml 2008-06-20 08:15:45+0100 i want to convert it to GMTi.e output after conversion should be 2008-06-20 07:15:45 using XSLT.I want changes to be done inside xslt only and no where else.Is this possible??

Link to comment
Share on other sites

Yes it is, you can create a quick function in xsl using the string manipulation functions such as substring-before(element,character), substring-after(element,character)... and the math operators (+,*,-...)But this will require some coding, I do not know if there is an already built function that'll do this.If you want a more complete answer, give a sample of your code.

Link to comment
Share on other sites

this template should do what you want. It accounts for either + or - in the offset. Only does hours, it you need minutes, shouldn't be hard

			<xsl:call-template name="convert2GMT">				<xsl:with-param name="localdate">2008-06-20 08:15:45-0300</xsl:with-param>			</xsl:call-template>		<xsl:template name="convert2GMT">			<xsl:param name="localdate"/>			<xsl:variable name="begin" select="substring-before($localdate,' ')" />			<xsl:variable name="after" select="substring-after($localdate,':')" />			<xsl:variable name="hour" select="substring(substring-after($localdate,' '),1,2)" />				<xsl:variable name="offsetoperator" select="substring($localdate,20,1)"/>			<xsl:variable name="offset" select="substring($localdate,21,2)" />			<xsl:value-of select="concat($begin,' ')"/>			<xsl:choose>				<xsl:when test="$offsetoperator = '+'">					<xsl:value-of select="substring(concat('0',$hour - $offset),1,2)"/>				</xsl:when>				<xsl:when test="$offsetoperator = '-'">					<xsl:value-of select="substring(concat('0',$hour + $offset),1,2)"/>				</xsl:when>			</xsl:choose>			<xsl:value-of select="concat(':',substring($after,1,5))"/>		</xsl:template>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...