0

We need function which will get execute and convert all datetime into Universal time format while storing into DB (we may have user locale as input also) and while retrieving back from DB pass users locale and convert that UTC into locale specific datetime stamp.

I'm using c#.net?

Please give me best lead on this one as I'm new to c#.

user1220402
  • 239
  • 1
  • 14
  • Have you heard of Google: [there you go](http://msdn.microsoft.com/en-us/library/system.datetime.touniversaltime.aspx) . ? – Noctis May 21 '14 at 03:30

2 Answers2

0

Having said the above, and believing it's a duplicate, I would still strongly suggest you understanding what you are facing.

DateTime & databases don't really mix well. They do in the sense that you can put a DateTime object in a database, but they don't in the sense that a time is not a precise representation.

I would highly recommend having a look at this video that tackles the problem in 10 minutes.

This is also why Jon Skeet wrote his Noda Time , because we humans, have a very fickle sense of time, and if that's not enough, the universe and it's laws have an even more funny sense of what it is (which leads us to keep changing and bending time to work the way we want).

Community
  • 1
  • 1
Noctis
  • 11,507
  • 3
  • 43
  • 82
0

Here see this snippets, its up to you how you can expand and utilizing this sample

//Get local Date
DateTime lD = DateTime.Now; // or DateTime.Today;

//Get utc date
DateTime utcD = DateTime.UtcNow;


//To Convert utc to local
//Using your OS default regional settings/time zone
DateTime fromUtcToLocal = utcD.ToLocalTime();

//To specific region/time zone of your choice
var tzi = TimeZoneInfo.FindSystemTimeZoneById("SE Asia Standard Time");
var choosenLocalTime = TimeZoneInfo.ConvertTimeFromUtc(utcD, tzi);

Some Time zone id

Dateline Standard Time
UTC-11
Samoa Standard Time
Hawaiian Standard Time
Alaskan Standard Time
Pacific Standard Time (Mexico)
Pacific Standard Time
US Mountain Standard Time
Mountain Standard Time (Mexico)
Mountain Standard Time
Central America Standard Time
Central Standard Time
Central Standard Time (Mexico)
Canada Central Standard Time
SA Pacific Standard Time
Eastern Standard Time
US Eastern Standard Time
Venezuela Standard Time
Paraguay Standard Time
Atlantic Standard Time
Central Brazilian Standard Time
SA Western Standard Time
Pacific SA Standard Time
Newfoundland Standard Time
E. South America Standard Time
Argentina Standard Time
SA Eastern Standard Time
Greenland Standard Time
Montevideo Standard Time
UTC-02
Mid-Atlantic Standard Time
Azores Standard Time
Cape Verde Standard Time
Morocco Standard Time
UTC
GMT Standard Time
Greenwich Standard Time
W. Europe Standard Time
Central Europe Standard Time
Romance Standard Time
Central European Standard Time
W. Central Africa Standard Time
Namibia Standard Time
Jordan Standard Time
GTB Standard Time
Middle East Standard Time
Egypt Standard Time
Syria Standard Time
South Africa Standard Time
FLE Standard Time
Israel Standard Time
E. Europe Standard Time
Arabic Standard Time
Arab Standard Time
Russian Standard Time
E. Africa Standard Time
Iran Standard Time
Arabian Standard Time
Azerbaijan Standard Time
Mauritius Standard Time
Georgian Standard Time
Caucasus Standard Time
Afghanistan Standard Time
Ekaterinburg Standard Time
Pakistan Standard Time
West Asia Standard Time
India Standard Time
Sri Lanka Standard Time
Nepal Standard Time
Central Asia Standard Time
Bangladesh Standard Time
N. Central Asia Standard Time
Myanmar Standard Time
SE Asia Standard Time
North Asia Standard Time
China Standard Time
North Asia East Standard Time
Singapore Standard Time
W. Australia Standard Time
Taipei Standard Time
Ulaanbaatar Standard Time
Tokyo Standard Time
Korea Standard Time
Yakutsk Standard Time
Cen. Australia Standard Time
AUS Central Standard Time
E. Australia Standard Time
AUS Eastern Standard Time
West Pacific Standard Time
Tasmania Standard Time
Vladivostok Standard Time
Central Pacific Standard Time
New Zealand Standard Time
UTC+12
Fiji Standard Time
Kamchatka Standard Time
Tonga Standard Time
Noctis
  • 11,507
  • 3
  • 43
  • 82
Jade
  • 2,972
  • 1
  • 11
  • 9