Questions tagged [datetimeoffset]

DateTimeOffset is a data structure that encapsulates a DateTime value and the Offset from UTC that the value reflects. It is used to represent an instantaneous moment in time, while still capturing the perspective of the observer.

DateTimeOffset is a data structure that encapsulates a DateTime value and the Offset from UTC that the value reflects. It is used to represent an instantaneous moment in time, while still capturing the perspective of the observer.

Contrary to popular belief (and to much of the documentation) the offset provided does not represent a time zone. One might start with a time zone to obtain the offset, but it is a one-way function. You can not determine the time zone by the offset alone. For a better understanding of this, see this community wiki answer.

The preferred serialization format for this type of data is defined as part of the ISO-8601 specification.

  • Example: 1997-07-16T19:20:30+01:00

DateTimeOffset and similar structures are presented in:

Please update this list if you are aware of similar structures in other languages, frameworks, or databases

614 questions
13
votes
3 answers

Difference between System.DateTime and System.DateTimeOffset

Can anyone explain the difference between System.DateTime and System.DateTimeOffset in C#.NET? Which is best suited for building web apps with users from different time zones?
Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
13
votes
3 answers

How do I update a column's offset in SQL Server?

I converted a table's DateTime field to DateTimeOffset, but now the offset is automatically set to +00:00. I need to change all DateTimeOffset fields of this table to an offset of +1:00. How can I do this in an update query?
Fred Fickleberry III
  • 2,439
  • 4
  • 34
  • 50
13
votes
1 answer

Will/Does MySQL support DATETIMEOFFSET?

I'm currently using a shared hosting plan, and I'm not sure which version of MySQL it's using, but it does not seem to support the DATETIMEOFFSET type. Does a version exists of MySQL that supports DATETIMEOFFSET? or are there plans for it to be…
CuriousGeorge
  • 7,120
  • 6
  • 42
  • 74
12
votes
1 answer

Entity Framework Mapping DateTimeOffset to SQL Server DateTime

Is there a way to map a DateTimeOffset property to a SQL Server datetime column, with the assumption that you can't change either side, meaning that the property and column have to stay those date types? I know the easiest is to make them match but…
Carlos
  • 223
  • 1
  • 2
  • 5
12
votes
4 answers

Json.NET deserializing DateTimeOffset value fails for DateTimeOffset.MinValue without timezone

In my ASP.NET Core Web-API project, I'm getting a HTTP POST call to one of my API controllers. While evaluating the JSON payload and deserializing its contents, Json.NET stumbles upon a DateTime value of 0001-01-01T00:00:00 and can't convert it to a…
12
votes
2 answers

How to compare two DateTimeOffSet?

I have a variable which is of type DateTimeOffSet. I'd like to filter all the projectS that were created after January 1st, 2010. So I've wrote the following query: var _date = new DateTimeOffset(2010, 01, 01, 0, 0, 0, new TimeSpan(-7, 0, 0)); …
Richard77
  • 20,343
  • 46
  • 150
  • 252
11
votes
2 answers

What would be the Python code to add time to a specific timestamp?

Trying to figure out datetime module and need some help. I've got a string which looks like this: 00:03:12,200 --> 00:03:14,316 (that is hours:minutes:seconds,milliseconds) and need to add let's say 10 seconds to each timestamp. To have as…
user63503
  • 6,243
  • 14
  • 41
  • 44
11
votes
1 answer

Store DateTimeOffset in SQLite.Net

In a WinRT (Windows 8.1 Store App) project, I'm using the SQLite.Net-PCL and SQLiteNetExtensions NuGet packages to store data in a local SQLite database file. Several of my data models (aka tables) contain properties of type DateTimeOffset. The aim…
andreask
  • 4,248
  • 1
  • 20
  • 25
10
votes
4 answers

C# convert datetimeoffset to string with milliseconds

The default toString() method in datetimeoffset converts the time into string format but loses the milliseconds. Is there anyway to preserve it?
Yang
  • 6,682
  • 20
  • 64
  • 96
10
votes
5 answers

Parse date time c# with correct timezone and kind

I have a datetime in database which I read using SqlDataReader and then cast it to (DateTime). After the cast its Kind property is DateTimeKind.Unspecified. Then I have another string which I read from some other source. Its format is like this…
Shikasta_Kashti
  • 701
  • 2
  • 13
  • 28
9
votes
5 answers

asp.net datetime randomly duplicate time offset. is a bug?

i have a website developed in asp.net 4 and sql server 2008 R2. The problem is very complicated. I have a field in db with datatime offset UTC (ex. 2015-09-30 18:24:53.1498113 +02:00). Randomly (i think when application pool restart) this value…
alex
  • 101
  • 2
9
votes
2 answers

How to properly work with Timezone?

I'm reading a lot about timezone, offset, utc, local time, javascript functions, DST, bacon and I 'm trying to put this all together to build a solid/correct structure for my app. Suppose my app is something like StackOverflow. That is how I'm doing…
Felipe Miosso
  • 7,309
  • 6
  • 44
  • 55
8
votes
1 answer

System.FormatException: The JSON value is not in a supported DateTimeOffset format

I was reading this MSDocs article about DateTime-related format support https://learn.microsoft.com/en-us/dotnet/standard/datetime/system-text-json-support#support-for-the-iso-8601-12019-format And I was trying to play around just to figure out that…
Natalie Perret
  • 8,013
  • 12
  • 66
  • 129
8
votes
1 answer

How to set the ZoneOffset for Berlin time zone

I am getting the LocalDateTime two hours lesser than the real time. How can I get the offset time for Berlin, Germany for the code below? LocalDateTime dateTime = LocalDateTime.ofEpochSecond(seconds, 0, ZoneOffset.UTC); DateTimeFormatter formatter =…
user9630935
  • 349
  • 1
  • 4
  • 18
8
votes
1 answer

Json.Net messes up timezones for DateTimeOffset when serializing

I have looked at a lot of related questions but none of them seem to be working for me. I'm trying to serialize everything in UTC. Here's my code: class Class1 { static void Main() { Class2 foo = new Class2(); JObject json =…
Zarwan
  • 5,537
  • 4
  • 30
  • 48
1 2
3
40 41