0

hello im mohammed from sri lanka and new to programing so i am litle bit confused these days

So we have a server in srilanka and we have clients are access to the website from several countries and make reservations then the server saves the time acording to srilankan time zone so i wont store actual time i need hep to resolve thease problems Helpme!and serve me!

EG:

client make order at 3.10am from USA it saves 3.10am and make Oder srilankan time 3.10 am so i want to atomatically conver to clint country time

how can i code that using C# visual studio 2010

thanks

4

1 回答 1

3

On the client side convert the time to GMT time using DateTime.ToUniversalTime and store it in your database. Then read it converting as local time zone.

E.g. in your code behind do something on the following lines. Code from MSDN.

System.DateTime univDateTime = localDateTime.ToUniversalTime();

to convert it back

System.DateTime localDateTime;
try {
    localDateTime = System.DateTime.Parse(strDateTime);
}
catch (System.FormatException) {
    System.Console.WriteLine("Invalid format.");
    return;
}
于 2012-05-25T09:14:26.257 回答