Menu
  • HOME
  • TAGS

Convert DateTimeOffset to DateTime and add offset to this DateTime

c#,datetime,datetimeoffset

Use DateTimeOffset.UtcDateTime: DateTime utc = myDTO.UtcDateTime; // 01/15/2015 22:37:00 ...

How do I resolve issues with unsupported DateTimeOffsets in EF 6 using Sql Server?

c#,.net,entity-framework-6,datetimeoffset

Facepalm! This issue was caused by a typo in the name of the connection string in the config file. Once I made sure the name of the connection string in the config matched the one supplied to the DbContext the problem disappeared. Of course, I was not helped by the...

How to properly parse DateTime string

c#,parsing,datetime,datetimeoffset

Given that you have a local time and an offset, I'd suggest representing that in DateTimeOffset. So: DateTime localTime = DateTime.ParseExact(...); DateTimeOffset offsetTime = new DateTimeOffset(localTime, offset); Then you still know the local time, but you can get the UTC equivalent when you want it. Basically it preserves all the...

DateTimeOffset parse and custom time zone

c#,timezone,timezoneoffset,datetimeoffset

The simplest way would be to test the string ahead of time to see if it contains an offset. Regular expressions work well for this. Here is a function that should work well for the case you described: static DateTimeOffset ParseAsDateTimeOffset(string s, TimeSpan defaultOffset) { if (Regex.IsMatch(s, @"(Z|[+-]\d{2}:\d{2})$")) return DateTimeOffset.Parse(s,...

dateoffset on dataframe column

python,pandas,datetimeoffset

You have 2 problems. firstly pandas.datetime is the datetime.datetime class not the module, so you need to reference the datetime.timedelta class directly. Secondly you need to take 1 day away from every value in the column. I would do: import datetime as dt df['expiration'] = df['expiration'].apply(lambda x: x - dt.timedelta(days=1))...

DateTimeOffset Same Day comparison

c#,datetimeoffset

Adjust the one of the dates for the difference in both dates: public static bool SameDate(DateTimeOffset first, DateTimeOffset second) { bool returnValue = false; DateTime firstAdjusted = first.ToUniversalTime().Date; DateTime secondAdjusted = second.ToUniversalTime().Date; // calculate the total diference between the dates int diff = first.Date.CompareTo(firstAdjusted) - second.Date.CompareTo(secondAdjusted); // the firstAdjusted date...

What does DateTimeOffset.Now.Offset.ToString() return when in daylight savigs time in the UK

c#,utc,gmt,datetimeoffset

DateTimeOffset.Now.Offset.ToString() would always return 00:00:00 if your timezone is UTC. Right. From documentation of DateTimeOffset.Offset property; The difference between the current DateTimeOffset object's time value and Coordinated Universal Time (UTC). As you can see, it is normal to get 00:00:00 since London is UTC±00:00 which is what we are...

Determine if the time an a certain timezone is within a range

c#,datetime,timezone,datetimeoffset

You're doing far more than you need to. Personally I'd use my Noda Time project, but all of this can be done fairly easily with the BCL, using TimeZoneInfo.ConvertTime: var zone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"); var centralTime = TimeZoneInfo.ConvertTime(DateTime.UtcNow, zone); if (centralTime.Hour >= 7 && centralTime.Hour < 21 && centralTime.DayOfWeek...

Forcing ISO 8601 with CSVHelper

c#,datetime,iso8601,datetimeoffset,csvhelper

You can simply provide the "o" format string to the type converter. Map(m => m.ChangeDT).TypeConverterOption("o"); ...

DateTimeOffset default value

default,datetimeoffset

The reason this code throws an exception for you is that you're presumably in a time zone which is ahead of UTC - so when DateTime.MinValue (which has a Kind of Unspecified) is converted to UTC, it's becoming invalid. The conversion is specified in the documentation: If the value of...

How to build custom pandas.tseries.offsets class?

python,pandas,matplotlib,datetimeoffset

As I mention in the comment, you potentially have two different problems You need to be able to plot a business times only timeseries without the long linear interpolations. You need an object that can do datetime arithmetic (in seconds) ignoring non-business times I've given a solution that will account...

C# (Windows Phone Silverlight) String to DateTime

c#,datetime,datetimeoffset

I would parse it to DateTimeOffset instead of DateTime since your string has UTC offset part. string s = "2015-07-30T11:11:00+0200"; DateTimeOffset dt; if(DateTimeOffset.TryParseExact(s, "yyyy-MM-dd'T'HH:mm:ssK", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)) { // } Now, you have a DateTimeOffset as 30.07.2015 11:11:00 +02:00 If you wanna get it's DateTime part, you can use...

Generate Date Time offset

c#,datetimeoffset

I think the month is a red herring, it's probably more likely your day is above 28 which means you are trying to create a date like 30th Feb (which doesn't exist!). Use the AddMonths method instead DateTimeOffset modified = input.AddMonths(-2); ...

ios swift get user time zone

swift,timezone,datetimeoffset

func ltzOffset() -> Int { return NSTimeZone.localTimeZone().secondsFromGMT } ltzOffset() // -7,200 if you need the abbreviation you can do like this: func ltzAbbrev() -> String { return NSTimeZone.localTimeZone().abbreviation! } ltzAbbrev() // "GMT-2" if you need the name you can do like this: func ltzName() -> String { return NSTimeZone.localTimeZone().name }...