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
30
votes
3 answers

Does Java 8's new Java Date Time API take care of DST?

I am thinking of using the new java 8 Date Time API. I googled a bit and found jodaTime as good choice for java but still kind of interested to see how this new API works. I am storing all time in UTC values in my datastore and will be converting…
Raja
  • 627
  • 1
  • 9
  • 24
28
votes
1 answer

How does DateTimeOffset deal with daylight saving time?

I am storing schedules in the database as a day of the week, hour and minute. When the data is read we create a DateTime object for the next occurrence of that day, hour and minute, but I need to modify this to be DST-aware. I am able to modify the…
Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
25
votes
9 answers

Strptime with Timezone

I have a String which I parse with DateTime.strptime. The Timezone of the Date in the String is CET but Ruby creates an UTC DateTime object which of course has an offset of 2hrs. Currently I'm working around the issue with…
Nicolas
  • 1,828
  • 6
  • 23
  • 34
25
votes
5 answers

how to convert string to DateTime as UTC as simple as that

assume I have this string : How can I convert it to DateTimeOffset object that will have UTC time - means -00:00 as Time Zone - even if I run it on machine on a specific timezone? Assume…
user1025852
  • 2,684
  • 11
  • 36
  • 58
24
votes
5 answers

Parse a date string into a certain timezone (supporting daylight saving time)

Ok i've been working very hard the last few weeks and i've come across a small problem. I don't think my mind is quite up to the task right now :) so i need some tips/help! it's likely very simple but my head isn't clicking yet. Users will enter a…
White Dragon
  • 1,259
  • 1
  • 8
  • 20
23
votes
3 answers

Is DateTimeOffset.UtcNow.DateTime equivalent to DateTime.UtcNow?

I need to upgrade some piece of code from statically calling DateTime.UtcNow to calling a time provider service which returns, basically, DateTimeOffset.UtcNow. To further convert this DateTimeOffset instance to DateTime, there is the DateTime…
Andrei Rînea
  • 20,288
  • 17
  • 117
  • 166
23
votes
2 answers

How to migrate DateTime values to DateTimeOffset in SQL Server?

Given a SQL table with a DateTime column and approx 100k rows of various dates (local time PST values) from the past 3 years, what is the best strategy to migrate those column values to DateTimeOffset to "add" the missing utc tz offset info? The…
mellodev
  • 1,597
  • 12
  • 20
22
votes
6 answers

Migrate SQL Server DateTime column to DateTimeOffset

I have an old table with a few rows that has a datetime column. I want to switch this to datetimeoffset but I want to be able to transfer the data that already exists. So I'm doing something like: SET IDENTITY_INSERT Table_Temp ON INSERT INTO…
hdz
  • 305
  • 1
  • 3
  • 9
21
votes
1 answer

Implementation strategy for Noda Time in an existing MVC5 application

Our application is a big n-tier ASP.NET MVC application that is heavily dependent on Dates and (local) Times. Up until now we have been using DateTime for all our models, which worked fine because for years we were strictly a national website,…
Fred Fickleberry III
  • 2,439
  • 4
  • 34
  • 50
19
votes
3 answers

How to convert a UTC DateTimeOffset to a DateTime that uses the systems timezone

Quartz.net offers a method to get the next time of the next trigger event: http://quartznet.sourceforge.net/apidoc/1.0/html/html/cc03bb79-c0c4-6d84-3d05-a17f59727c98.htm The docs claim that this Trigger.GetNextFireTimeUtc() method return a DateTime?…
Dan
  • 45,079
  • 17
  • 88
  • 157
18
votes
5 answers

Python: third Friday of a month

I am a rookie python programmer and I need to write a script to check if a given date (passed as a string in the form 'Month, day year') is the third Friday of the month. I am using Python 2.7. For example, these dates can help you better understand…
Juan Catalan
  • 2,299
  • 1
  • 17
  • 23
17
votes
2 answers

Working with Time Zones in SSRS

We store all our dates SQL Server 2008 database in UTC time in DateTime columns. I'm using SSRS to create reports and I need to convert all the times on the reports to the Time Zone of the computer where they're running the report from. I know…
jamiegs
  • 1,761
  • 2
  • 15
  • 23
16
votes
2 answers

Is it possible to serialize DateTimeOffset to zulu time string with Json.NET?

I have a DateTimeOffset object of "05/06/2014 05:54:00 PM -04:00". When serializing using Json.NET and ISO setting, I get "2014-05-06T17:54:00-04:00". What I would like to have is the UTC/Zulu version of that string "2014-05-06T21:54:00Z". However,…
Zoomzoom
  • 1,042
  • 2
  • 13
  • 32
14
votes
1 answer

Remove Time Zone Offset from DateTimeOffset?

This code: DateTimeOffset testDateAndTime = new DateTimeOffset(2008, 5, 1, 8, 6, 32, new TimeSpan(1, 0, 0)); //CLEAN TIME AND DATE testDateAndTime = testDateAndTime.DateTime.Date; var datesTableEntry = db.DatesTable.First(dt => dt.Id ==…
VSO
  • 11,546
  • 25
  • 99
  • 187
14
votes
3 answers

Unit testing NHibernate w/ SQLite and DateTimeOffset mappings

Porting over an application to use NHibernate from a different ORM. I've started to put in place the ability to run our unit tests against an in memory SQLite database. This works on the first few batches of tests, but I just hit a snag. Our app…
bakasan
  • 2,262
  • 2
  • 26
  • 33
1
2
3
40 41