Convert UTC DateTime to DateTimeOffset

Here is the solution you are looking for: const string dateString = “2012-11-20T00:00:00Z”; TimeZoneInfo timezone = TimeZoneInfo.FindSystemTimeZoneById(“W. Europe Standard Time”); //this timezone has an offset of +01:00:00 on this date DateTimeOffset utc = DateTimeOffset.Parse(dateString); DateTimeOffset result = TimeZoneInfo.ConvertTime(utc, timezone); Assert.AreEqual(result.Offset, new TimeSpan(1, 0, 0)); //the correct utc offset, in this case +01:00:00 Assert.AreEqual(result.UtcDateTime, new DateTime(2012, … Read more

The UTC time represented when the offset is applied must be between year 0 and 10,000. Parameter name: offset

The DateTimeOffset constructor first converts any DateTime that is not of Kind ‘UTC’ to the equivalent UTC time. It will then check whether the UTC-equivalent DateTime falls outside of the bounds of DateTimeOffset.MinValue and DateTimeOffset.MaxValue, and if it does, will throw an ArgumentOutOfRangeException similar to the one you are experiencing. Check the DateTime.Kind of the … Read more

How can I convert a Sql Server 2008 DateTimeOffset to a DateTime

Converting using almost any style will cause the datetime2 value to be converted to UTC. Also, conversion from datetime2 to datetimeoffset simply sets the offset at +00:00, per the below, so it is a quick way to convert from Datetimeoffset(offset!=0) to Datetimeoffset(+00:00) declare @createdon datetimeoffset set @createdon = ‘2008-12-19 17:30:09.1234567 +11:00’ select CONVERT(datetime2, @createdon, 1) … Read more

Determine Whether Daylight Savings Time (DST) is Active in Java for a Specified Date

This is the answer for the machine on which the question is being asked: TimeZone.getDefault().inDaylightTime( new Date() ); A server trying to figure this out for a client will need the client’s time zone. See @Powerlord answer for the reason why. For any particular TimeZone TimeZone.getTimeZone( “US/Alaska”).inDaylightTime( new Date() );

Best practices with saving datetime & timezone info in database when data is dependant on datetime

Hugo’s answer is mostly correct, but I’ll add a few key points: When you’re storing the customer’s time zone, do NOT store a numerical offset. As others have pointed out, the offset from UTC is only for a single point in time, and can easily change for DST and for other reasons. Instead, you should … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)