Solution on how to convert DateTime variables between UTC and Local or a specific timezone

  1. Convert from UTC to a specified timezone.
    We can use the TimeZoneInfo.ConvertTimeFromUtc static method in an Assign activity (Invoke Method can work as well), setting first parameter to the UTC DateTime object and the second parameter to a TimeZoneInfo object which represent the target Timezone. The TimeZoneInfo object can be created with the help of TimeZoneInfo.FindSystemTimeZoneById method where we need to specify the name of the timezone we want, like India Standard Time or Tokyo Standard Time.

  2. Convert from a specified timezone to UTC
    We can use the TimeZoneInfo.ConvertTimeToUtc static method in a similar way as above, just that the second parameter is used to specify the source timezone. Note: the source DateTime object must have the Kind property set to DateTimeKind.Unspecified.

Please check the attached workflow or project to see how to use the above methods to convert the result of an activity from the Cron Expression package.
CronToLocalTime.xaml (15.2 KB)
CronExpressionTimezone.zip (7.0 KB)
The project was created in UiPath Studio 2019.10.2 and it references the UiPathTeam.CronHelper.Activities package which can be found in the Go! feed or on UiPath Go!. The project contains a single workflow, the one attached here. In case you canā€™t open the project, download the workflow and add it in a new project and reference the UiPathTeam.CronHelper.Activities package.

This post was created to answer a question for the Cron Expression component available on UiPath Go!

2 Likes

image

Since, my current cron expression is based upon to run on IST (+5:30 GMT) timezoneā€¦in which zone is it returning the next run time. PFA screenshot from VM which is in PST timezone(-8:00 GMT)

1 Like

Hi, can this be considered as a FAQ (and maybe moving to that forum category)?

Can we have activity where we input 2 params: TimezoneInfo and cron expression and it gives output in that particular timezone time.

@devashish1989, the activity is returning the next run time in UTC timezone. But the time expressed in the cron expression is interpreted as Local Time. Iā€™m considering your suggestion to update the activity with the Timezone info as well, but it will take some time to do it.
For the moment, you can write the Cron Expression considering the time difference between your local Timezone and the desired Timezone (IST) and then convert the resulting time to the desired Timezone (IST).

Yes, maybe it fits better the FAQ section, thanks for the suggestion. I canā€™t move it myself, but maybe an admin can help.

1 Like

Hi,

I am working on convert timezone. In my workflow I have captured system date and time. And I need to convert it into CST format.
Could you please help me on this.

Hi @vaishnavi_baradkar,

You could use the TimeZoneInfo.ConvertTimeFromUtc method to convert to the CST timezone. BTW, what is CST? Central Standard Time, China Standard Time?
But, for that you need to capture the current time in UTC format using the DateTime.UtcNow property.

Here you have an example on how to do that: CurrentTimeToSpecificTimezone.xaml (5.9 KB)

Regards
Silviu

4 Likes

Assign Timezone Info: The time zone ID ā€˜Central Timeā€™ was not found on the local computer.
this error is coming when tried to convert UTC to CT zone, can any one help me
@Silviu

1 Like

Check this article as it may help you (get the UTC time, then add/subtract the needed hours in order to match your timezone) Change Timezone - #16 by marian.platonov

1 Like

This saved me, thank you!! This allows me to upconvert three of my processes to the new Windows version in Studio 2022.10. I was previously using a non official package to do this, which I could not use in the new Studio.

Thank you so much!!

To change date time from local to another time zone.

Steps:

  1. Get the date time value of local zone or the date time value that needs to be converted. (localDateTime = DateTime.Now)
  2. Assign Time Zone to which above date time value has to be converted to a string variable. (timeZone = ā€œEastern Standard Timeā€)
  3. Use assign activity to convert the date time value and assign it to a date time variable.
  4. Syntax -

Result DateTime variale = System.TimeZoneInfo.ConvertTime(localDateTime,System.TimeZoneInfo.Local, System.TimeZoneInfo.FindSystemTimeZoneById(timeZone))

ā€œlocalDateTimeā€ and ā€œtimeZoneā€ are the date time and string variable respectively defined above.

Please refer the code below to understand the method.
GetTimeAccZone.xaml (7.3 KB)

Hello @Silviu ,

When I convert from UTC to a target timezone, do you know if the target timezone automatically adjusts for daylight savings time when it happens?

Thanks!