Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DateTime timezone behavior
Message
De
05/11/2008 18:31:37
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
DateTime timezone behavior
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:
01360004
Vues:
62
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.
Timothy Bryan
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform