Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DateTime timezone behavior
Message
 
 
À
05/11/2008 18:31:37
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 3.0
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
MS SQL Server
Divers
Thread ID:
01360004
Message ID:
01360025
Vues:
10
>I have a strange thing happening to my DateTime field in every record being saved to SQL Server. My SQL Server is in Texas (central time zone) but my application is running in pacific time. The computer has the correct pacific time zone time set on it. Every record in the SQL Server database has this time set two hours ahead.
>
>I am getting my time from DateTime.Now and then setting a property in an Entity that gets saved to the table.
>>pre>
>.. bunch of code
>//Reset the lastLogTime
>this.lastLogTime = DateTime.Now;
>.. some code that doesn't touch the lastLogTime
>// Build the SpotStarter object
>SpotStarterEntity oSpotStarter = new SpotStarterEntity();
>
>oSpotStarter.Track_id = Guid.NewGuid();
>oSpotStarter.Record_Status = type;
>oSpotStarter.Spot_Latitude = lat;
>oSpotStarter.Spot_Longitude = lon;
>oSpotStarter.Spot_Time = lastLogTime;
>... Set more properties in the Entity
>// Save this Entity
>
>
>Since I am also in CT I don't know if I can conclusively test this, but I suppose I could change my computer timezone to something else and try that. Anybody have any ideas why this would happen.
>Tim
>
>Updated: Ok, I forgot to mention that I am using Mere Mortals framework which I will work through and also WCF to get the data up to the server. Might be something in those things, as DateTime.Now sure should just get local computer time.

I think you should always save data in UTC format on the server and display them in local format.
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform