Android emulator does not do DateTime.Now correctly

Lloyd Sheen 1,486 Reputation points
2023-03-13T18:12:52.1466667+00:00

I have a control that will show a list of items for a day. If the time when the app is run is before noon it will show the last day's items and after noon it will show items for that day.

Now I am not sure if this ever worked as to test I created my own DateTime so it would work.

When I take out the line to set the time I get the following:

3/13/2023 1:26:08 PM from DateTime.Now

3/13/2023 2.04 PM is actual time.

Now I thought it might have to do with Daylight saving time but the difference is about 38 mins so I have no idea what is happening. I created a WPF app and put the DateTime.Now in it and it returns the correct DateTime. I first thought that I needed to set a timezone for the emulator but 38 mins is not a resetable time that I know of.

I assume that the returned DateTime is set by the code running in the emulator. If I run the code using my phone the return value of .Now is correct.

Any ideas as I will have other requirements that are time dependent.

Developer technologies | .NET | .NET MAUI
{count} votes

1 answer

Sort by: Most helpful
  1. Lloyd Sheen 1,486 Reputation points
    2023-03-15T11:53:31.94+00:00

    To reset the time on the emulator you can delete it and re-add it or do a factory reset on the emulator to get the correct time.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.