Monday, October 14, 2024

OIC - How to convert from one timezone to another timezone

Usecase: Here we will demonstrate how to convert from UTC to IST timezone. We can convert to any other timezones.

Currently my oic instance timezone is in UTC and I have one requitement to convert it to IST timezone.

We have to use below functions:

  • Adjust-dateTime-to-timeZone() 
  • dayTimeDurarion()

Solution code:

fn:string(fn:adjust-dateTime-to-timezone(fn:current-dateTime(), ns0:dayTimeDuration('PT5H30M')))

Screenshots:



Notes:

How to get the duration:

From https://www.worldtimebuddy.com >> add place or timezone and can see the time difference with the UTC. Like for IST, its showing +5.5 hrs difference.


Duration syntax:

Now question is how to get the PT5H30M value and what syntax it follows:

  • P is the duration designator (for period) placed at the start of the duration representation.
  • Y is the year designator that follows the value for the number of years.
  • M is the month designator that follows the value for the number of months.
  • W is the week designator that follows the value for the number of weeks.
  • D is the day designator that follows the value for the number of days.
  • T is the time designator that precedes the time components of the representation.

So P means 'Period' and because there are no date-components it only has a 'Time'. You could interpret this as 'Period of Time'

The details for the time component are:

  • H is the hour designator that follows the value for the number of hours.
  • M is the minute designator that follows the value for the number of minutes.
  • S is the second designator that follows the value for the number of seconds.

Example

durarion("P1Y2M3DT10H30M") : represents a duration of 1 year, 2 months, 3 days, 10 hours and 30 minutes.

Duration("PT2000H") : represents a duration of 2000 hours.

We not only convert from date time, we can also convert from date to timezone or time to timezone. To achieve this, OIC has OOTB below functions:

  • adjust-dateTime-to-timeZone()
  • adjust-date-to-timeZone()
  • adjust-time-to-timeZone()

Example of fomatting after the timezone change.
xp20:format-dateTime (fn:adjust-dateTime-to-timezone (fn:current-dateTime(), xsd:dayTimeDuration ("PT8H") ), "[D01][M01][Y0001][H01][m01][s01]" )

No comments:

Post a Comment

Featured Post

11g to 12c OSB projects migration points

1. Export 11g OSB code and import in 12c Jdeveloper. Steps to import OSB project in Jdeveloper:   File⇾Import⇾Service Bus Resources⇾ Se...