3

How to convert GMT time to local time ( MDT or MST ) automatically.

I got this below working but i need a condition which determines utc -6 or utc -7 based on dates.

<xsl:value-of select="xs:dateTime($docdate) + xs:dayTimeDuration('-PT7H')"/>

Thanks Hari

hari
  • 31
  • 1
  • 6

2 Answers2

2

You might look at the function adjust-time-to-timezone($arg as xs:time?), which adjusts the time given in $arg to the implicit timezone given in the dynamic context. There are no guarantees, but in many implementations that is likely to be the timezone set in the operating system environment.

For example, if I evaluate the expression

adjust-time-to-timezone( xs:time('20:45:00.0+01:00'))

my system (current set to 7 hours west of UTC) returns the value

12:45:00-07:00
C. M. Sperberg-McQueen
  • 24,596
  • 5
  • 38
  • 65
  • It worked fine from stylus studio. But when i used in sap ..i couldn't compile the xsl and got the error saying "Error has occurred during XSL transformation Could not compile stylesheet" [link]http://temp-share.com/show/f3Yg9O92n [link]http://temp-share.com/show/3YgFpWkRx has xml and xslt files. – hari Feb 08 '13 at 00:21
  • Any idea on what could be the problem? – hari Feb 08 '13 at 00:30
  • Your XSLT stylesheet says it's a version 1.0 stylesheet, but the adjust-dateTime-to-timezone and xs:dateTime functions are 2.0 functions. If the XSLT engine you're using in SAP supports 2.0, try changing the version attribute on the stylesheet element. But 2.0 processors typically handle this kind of thing without blowing up, so your system may be trying to tell you, in its way, that it cannot handle 2.0 functions. – C. M. Sperberg-McQueen Feb 08 '13 at 03:25
  • Thanks C.M. , That's what i thought..but wanted expert opinion. So,what is the way left for me to do that date manipulation in XSLT 1.0 ? – hari Feb 08 '13 at 16:36
  • XSLT 1.0 doesn't have much in the way of environment queries, but if your processor supports the EXSLT date-time functions you might be able to use [exslt:date-time()](http://www.exslt.org/date/functions/date-time/index.html) to determine your operating system's current offset from UTC. – C. M. Sperberg-McQueen Feb 08 '13 at 17:36
-1

You can use a script, for example a javascript using javascript dates.

Mihai8
  • 3,113
  • 1
  • 21
  • 31
  • So, are you saying i can write JS in XSL? if yes,would you provide me an example? – hari Feb 06 '13 at 22:31
  • A first example that I found is http://www.webdeveloper.com/forum/showthread.php?20815-Using-Javascript-in-XSL – Mihai8 Feb 06 '13 at 22:52
  • would only work in an xslt engine that supported javascript, presumably in a browser or javascript already. – dezzer10 Mar 26 '18 at 16:02