-1

I need to convert a utc datetime to a local datetime.

it should look something like this:

private DateTime localdate (DateTime UTC_DateTime)
{

DateTime local =  new DateTime();
local  = UTC_DateTime .....         ??? 

return local;

}

Thanks in advance for your Help!

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Eray Geveci
  • 1,099
  • 4
  • 17
  • 39

2 Answers2

1

Do it like so:

private DateTime Localdate (DateTime utc_DateTime)
{

    DateTime local =  new DateTime();
    local  = utc_DateTime.ToLocalTime();

    return local;

 }

But the method itself is "a bit" redundant. Just a recommendation: Try to respect the "Pascal-case convention" embraced by C# which states that method names are capitalized and that parameter names are not (amongst other things).

Eduard Dumitru
  • 3,242
  • 17
  • 31
0

use method DateTime.ToLocalTime()

burning_LEGION
  • 13,246
  • 8
  • 40
  • 52