Changing timezone in datetime utility

Hi,

I’m completely new to Pega robotic process automation so I would like to ask if there is a way on how to change or set the timezone using datetime utility perhaps?

@RodelD25 I am not quite sure what you are asking for. Would you be able to give me an example? Are you trying to change the time zone on the local machine, or are you converting a DateTime object from one time zone to another (or something else perhaps)?

Hi @ThomasSasnett I’m trying to convert a local time in my machine into a different time zone. For example my current time zone in my machine is in Asia Pacific and I want it to convert into Central Standard Time in the bot rather than changing the time zone itself in the machine. This way whoever uses the bot and whatever time zone is in their local machine it will always be converted into the time zone set in the bot.

@RodelD25 Here is an example. You need to add some static methods from the Global Assembly Cache. To do that;

  1. Right-click on the Toolbox and select “Choose Items…”.
  2. Select the “Pega Robot Static Members” tab.
  3. Select the “From Global Assembly Cache” radio button.
  4. From the “Assembly” combo box, select the latest version of “mscorlib”.
    • I like to click the letter “N” on my keyboard and scroll up to find it quicker as it is alphabetically closer to N than M.
  5. Locate the TimeZoneInfo node and check the following; ConvertTimeToUtc and ConvertTimeFromUtc.
    • This step may not be necessary, but it is the easiest to demo what we are doing and in an automation is actually fewer steps than how you’d do this in C#.
  6. Once these are checked (you may also add anything else in here you find useful: I have found uses for the NewGuid method a lot as well as several items under Environment), you may click “OK” to add them to your Toolbox.
  7. Now you can use these items in an automation.

In my example, I am using a DateTimeUtils to get the current time using the Now method. I then call the FindSystemTimeZoneById method which returns a TimeZone object for the specified Id. You’ll have to search for these IDs, but I did include the one you asked for. Then I converted it to UTC so that I could then convert it from UTC. This is really just for the automation. In code, you would just do this directly, however I would need to create a TimeZone object for the current time which would be more automation steps.

Project77.zip (14.9 KB)

@ThomasSasnett thank you so much for your help.