Every now and then I need to convert a date from Coordinated Universal Time (UTC) to Eastern Standard Time (EST). I always found myself trying to remember: Where did I use this last?. To avoid asking myself, I have now immortalized it on my blog. The solution leverages TimeZoneInfo.ConvertTimeFromUtc. The following will use C# convert utc to timezone and C# convert datetime to utc. This is of course not limited to EST and can be used to c# datetime utc+8 (e.g. utc to rst).
Tag: c#
-
C# String Extension to Split Camel Case
Let me show you a quick method to convert Camel Case in C# to title case.
-
Random number generator only generating one random number
To generate a random number it involves instantiating the Random class then calling the Next function with a minimum and maximum value as follows: new Random().Next(min, max) so why is it always returning the same number? This commonly occurs when this is being called in a loop.
-
Solution to SameSite None iFrames with C#
There has been a lot of kerfuffle over Chrome’s upcoming change to how cookies are based when one website is iFraming another website in an effort to further improve the security of the Internet.
At the end of the day, the solution is to set your cookies – specifically the .ASPXAUTH cookie – so that when users navigate the website of the iFrame source the cookies will be passed from page-to-page. This is very important to those who are using FormAuthentication.
The solution requires two changes. Let’s look at them now.
-
Deep clone an object with C#
Cloning is a common thing I need to do in my C# project. The most common case I use this is with my Entity Framework projects. I first fetch my object using a standard Linq query.
Once I have this object, EF is now tracking any changes to the object. I want a duplicate object of this so I can track a before and after state, so I want to clone the fetched object. To do this I use JSON.Net nuget package.