When I get the value of a dateTimeOffset column from the database using EntityFrameworkCore I get the value of that column in Hijri when CurrentCulture & CurrentUICulture of the current thread is Arabic(ar-SA).
I know that if I changed the CurrentCulture of CurrentThread before returning that value I would get it in Gregorian calendar.
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-UK");
But how can I return it as dateTimeOffset in Gregorian calendar without changing CurrentCulture of the CurrentThread?
Your assertion that the current culture affects how the EF Core creates the
DateTimeOffset instance is incorrect.
DateTime data types do not have a calendar unto themselves, and the thread's current culture does not affect how they are created (unless parsing from a string).
However, some instance methods, such as
ToString, will use the current culture when they are called, unless otherwise specified. Likely you are seeing string output created by
ToString (whether explicitly or implicitly), and seeing the thread's current culture affecting the output there.
Therefore, simply pass a specific culture (often the
InvariantCulture) to the
ToString method, and you will see the output in the Gregorian calendar.
string myString = myDateTimeOffset.ToString(CultureInfo.InvariantCulture);