0

I'm trying to convert a timestamp to DateTime object in C# interactive using DateTime.UnixEpoch.

I have no problem doing it in my application code, but I can't get access to DateTime.UnixEpoch in C# Interactive.

I managed to convert a timestamp using suggestion from this StackOverflow post. It works in C# interactive just fine.

Now I'm curious why does DateTime.UnixEpoch accessable in my regular code and does not in my C# interactive envinroment.

I'm using Visual Studio 2022 17.7.3 and my project targeting .NET 7.0

Here is my code in C# interactive:

> double timeStamp = 1693620016;
. DateTime dateTime = DateTime.UnixEpoch;
. dateTime = dateTime.AddSeconds(timeStamp);
. Console.WriteLine(dateTime.Date);

Here is the Output:

(2,30): error CS0117: 'DateTime' does not contain a definition for 'UnixEpoch'
Ivang
  • 11
  • 4
  • What version of .NET is your csproj targeting? The UnixEpoch member isn’t in .NET Framework 4.x. – Dai Sep 02 '23 at 06:14
  • @Dai I'm using .NET 7.0 – Ivang Sep 02 '23 at 06:18
  • Tried this? https://stackoverflow.com/questions/65232414/how-can-i-use-net-core-in-c-sharp-interactive – Dai Sep 02 '23 at 06:39
  • @Dai You are right. Swithching to core by using "#reset core" command solved my problem. I've also noticed that there is a targeting framework in the header of the C# interactive window and one can choose between .Net Framework 32 or 64 or .Net Core. Thanks for help! – Ivang Sep 02 '23 at 10:08

1 Answers1

1

In C# Interactive enter the following command:

#reset core

This command swithches target framework for C# interactive.

The current target framework can be found on the title of the C# Interactive tab.

The answer from the StackOverflow post suggested by @Dai worked here.

Ivang
  • 11
  • 4