cancel
Showing results for 
Search instead for 
Did you mean: 

Convert UTC DateTime to Local Date Time

ChristianPanhan
Level 6
Hello, using the Now() Function in a calculation stage I get the representation of Date an Time in UTC. But what is, when I already have an UTC-Datetime and after all calculation is done I like to convert this to Local Date Time for user output. How can I accomplish this? I know, that there are two other functions in a calculation stage UTCTime() and LocalTime() but they are only returning a Time-Value without the date part. And what I need is both - Date and Time. I also tried doing this in a code stage. For example: ------ DateTime dtutc; DateTime dtlocal; TimeZoneInfo infoLocal = TimeZoneInfo.FindSystemTimeZoneById("Central European Standard Time"); dtutc = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc); dtlocal = TimeZoneInfo.ConvertTimeFromUtc(dtutc, infoLocal); Console.WriteLine(dtutc.ToString()); Console.WriteLine(dtlocal.ToString()); ---- This code works perfectly at home on my private PC, because the difference between UTC and Local-Time is exactly the 2 hour difference from UTC to the time in my country. But the same code - exception Console WriteLine - in Blue Prism I get exactly the same value for UTC an Local Time. Why is this? What am I missing? Thanks    
2 REPLIES 2

John__Carter
Staff
Staff
Try the attached Chris. Admittedly, it should be a lot easier https://portal.blueprism.com/products/enhancement-request

Anonymous
Not applicable
BluePrism converts all non-UTC DateTime back to UTC on Code Stage output as described in documentation (page 3): https://portal.blueprism.com/system/files/2017-11/v6%20Data%20Sheet%20-… Workaround to this is setting local time to DateTime instance and specifying it's kind property to UTC: ---------------------- DateTime dtutc; DateTime dtlocal; TimeZoneInfo infoLocal = TimeZoneInfo.FindSystemTimeZoneById(""Central European Standard Time""); dtutc = DateTime.SpecifyKind(DateTime.UtcNow, DateTimeKind.Utc); dtlocal = TimeZoneInfo.ConvertTimeFromUtc(dtutc, infoLocal); dtOutput = DateTime.Specifykind(dtlocal, DateTimeKind.Utc).ToString(); ------------------------ Above will assing your local time converted from UTC and assign it to output without converting back to UTC.