-1

I'm having trouble storing time in database due to the current datetime which is out dated. How can i programatically change the date and time of the system so that the values stored should be correct even if the system date and time is not correct. I've used timezone but it didn't help as it gets the same time and date which is set on the system.

var euTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Pakistan Standard Time");

DateTime euTime = TimeZoneInfo.ConvertTime(System.DateTime.Now, TimeZoneInfo.Local, euTimeZone);

TimeSpan timeOfDay = euTime.TimeOfDay;
Nagaraj S
  • 13,316
  • 6
  • 32
  • 53
Salar Muhammad
  • 334
  • 1
  • 8
  • 21
  • 2
    To keep it short: Its not your business! At least its not a task for your app. Configure time sync in the system to resolve this error. The app could detect the error, but it can't handle it! – Tom Schardt Nov 20 '17 at 06:09
  • You mean every system must be manually corrected with date and time? Like as you mentioned about time sync. – Salar Muhammad Nov 20 '17 at 06:13
  • look at [this answer](https://stackoverflow.com/a/650872/2495004) – Albert Nov 20 '17 at 06:49
  • 3
    You don't "manually" correct the system time. This is what [NTP](https://en.wikipedia.org/wiki/Network_Time_Protocol) is for and what @TomSchardt is referring to. – Markus Deibel Nov 20 '17 at 07:03
  • @user100020 - Please clarify, are you saying that you do not want to trust that your own server's clocks are set correctly (which would be an OS issue)? Or are they set correctly but you want to convert to a specific time zone (which would be a code issue)? – Matt Johnson-Pint Nov 20 '17 at 15:42
  • May be its an OS issue, cuz whenever i switch on to my system or restart it, the time is always changed. – Salar Muhammad Nov 21 '17 at 04:13

1 Answers1

0

You cannot modify system Datetime but you do have option to get the datetime of a particular timezone using an API. If you know the timezone of client then sending just location to this web API should return the correct time of that region irrespective of local time on system.

For web API you can use https://developers.google.com/maps/documentation/timezone/intro

Abhishek Maurya
  • 321
  • 1
  • 3
  • 13