Today's Date and Time

Hi Team,

I am having use case where I need to validate/ compare a date received from server with local date.

For example I received date from the server is 30th June 2024 And I need to compare the server date is greater than today's date or not.

Based on this, I need to allow user to continue access of feature.

But iphone user can change the date time of device from iphone's setting option. For example from today to previous month date. So when I tried to compare the server date which I have stored locally is always ahead of today.

I can not fetch date from server again and again.

How do I get exactly real date even though user has changed device date without fetching from any server?

Why do you need to do this?

You have control over the server, right? The user cannot affect the server's date time, so:

  • If the device date is before the server date, then don't allow them to do something.
  • If the device date is after the server date, then you know it's rubbish because the user has changed their device date to be after the server date.

The server date should be the one source of truth. That's always the correct date. Deal with it like that, and you should be fine.

Today's Date and Time
 
 
Q