Timestamp format when it contains time zone

Hello experts
I am new to uipath and trying to read mail timestamp from Gmail using imap activities .
I am trying to parse date/timestamp using Datetime.ParseExact and convert to string. I would like to know what will be format string for this function when date/ timestamp are given in format below
Mon, 23 Nov 2020 15:31:54 +0000
Mon, 23 Nov 2020 02:18:45 -0600 (CST)
Sun, 22 Nov 2020 23:59:53 -0800

As of now I am using format like this
“ddd, d MMM yyyy HH:mm:ss -0600 (CST)”
Bu it will work for format given in example 2.
But time zone part is not fixed so I wonder how can I handle this.
Thanks in advance.

Hi,

Can you try the following? Perhaps first you should remove (CST), in order to normalize its format.

text = System.Text.RegularExpressions.Regex.Replace(x,"\(.*?\)$","").Trim
DateTime.ParseExact(text,"ddd, dd MMM yyyy HH:mm:ss zzz",nothing)

Regards,

1 Like

Thanks a lot . It’s working .However I believe this converts into UTC . Can I change it to local time zone . Let’s say IST.

Hi,

Can you check Kind property of your DateTime variable (like dtVar.Kind )? Probably it’s recognized as Local.
If you want to change UTC to Local or Local to UTC, DateTime.ToUniversalTime() or DateTime.ToLocalTime() helps you…

Regards,

Thanks a lot . I will figure out based on hint given.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.