Save GMT dates on an American server

I am from the UK and recently hosted a site on WinHost Basic Package .

When used DateTime.Now()in C # or GETDATE()in SQL, they return something like GMT-8(because the server is located in the USA).

I think I'm a bit limited in terms of server permissions (for example, I cannot change my SQL login language).

What is the best way to store these dates in GMT?

+3
source share
3 answers

Description

I think you should store your DateTimes in UTC. Then you can simply convert it to another time zone with the TimezoneInfo class.

  • Save DateTime.UtcNowin your database or use getUtcDateinside sql
  • .
  • UTC, , TimeZoneInfo.ConvertTimeFromUtc

TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById(/* destination timezone (users timezone)  */);
DateTime cstTime = TimeZoneInfo.ConvertTimeFromUtc(YourDateTimeFromDatabase, cstZone);

+2

DateTime.UtcNow . UTC UK TimeZoneInfo. , SQL .

+4

SqlServer getUtcDate(), datetime. .NET.

+3

All Articles