UTC time handling in C #?

I'm not an expert on C # internals, so this question can be completely stupid. If yes, please correct me. I have some data (in UTC format) extracted from a SQL server.

2011-03-26 11:03:58.000
2011-03-26 11:04:25.000
...

I parse this file inside C # and use the following:

DateTime date = DateTime.Parse(value);

to get the value into the object DateTime. Now I subtract some arbitrary time of 6 hours from this time as follows:

date = date.Subtract(new TimeSpan(6, 0, 0));

And finally, I write this back to another file as follows:

output.WriteLine(date.ToString("yyyy-MM-dd HH:mm:ss.fff"));

, UTC. , / , , UTC #, ? , . -, , ?

: UTC. / UTC. , , .. #, UTC, , , UTC.

+5
5

. - , , . , Net , .

, DateTime.SpecifyKind(value, DateTimeKind.Utc).

+4

SQL Server. ADO.Net SqlDateTime datetime . ORM (LinqToSQL, Entity Framework ..) datetime datetime. , , ( SET DATEFORMAT...)

, . UTC UTC datetime:

UPDATE table SET column = DATEADD(hour, 1, column) WHERE ...
+3
+2

, DateTime.Parse, DateTimeStyle, .

string utcDateString = "2011-03-26 11:03:58.000";

DateTime localDate = DateTime.Parse(utcDateString, 
                          CultureInfo.CurrentCulture, 
                          DateTimeStyles.AssumeUniversal);

DateTime utcDate = localDate.ToUniversalTime();

localDate . EDT () 7:03:58. utcDate 11:03:58, .

+1
source

All Articles