datetimeoffset

WCF DateTimeOffset compatibility

懵懂的女人 提交于 2019-12-22 05:14:50
问题 I have a .NET WCF service with a few operation contracts that takes a DateTimeOffset. The idea is to avoid any confusion with DST and time zones. However I am in doubt that using DateTimeOffset is a good idea after all, since it is fairly non-standard and would cause headaches for anyone trying to connect with, say, a Java application or a .NET application bound to an older .NET version. An alternative is to expect a UTC DateTime, but this introduces the risk that someone will forget to use

Converting DateTime.MinValue to DateTimeOffset

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-22 05:13:45
问题 I am trying to convert DateTime.MinValue to a DateTimeOffset value but am getting an ArgumentOutOfRange exception. I was looking at the the MSDN article on implicit conversions of DateTime to DateTimeOffset and the Exception section states that I'll receive this ArgumentOutOfRange exception when; ... The Coordinated Universal Time (UTC) date and time that results from applying the offset is earlier than MinValue. ... Why then does the following code throw the exception; DateTime test =

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

隐身守侯 提交于 2019-12-22 04:06:33
问题 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, I could not find any serializer setting to achieve this. I know for DateTime serialization, I can set DateTimeZoneHandling = DateTimeZoneHandling.Utc to have the Zulu format. However, there isn't such setting option for DateTimeOffset. Am I missing

Remove Time Zone Offset from DateTimeOffset?

雨燕双飞 提交于 2019-12-21 04:17:15
问题 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 == someTestId); datesTableEntry.test= testDateAndTime; db.SaveChangesAsync(); ...produces this result in my database: 2008-05-01 00:00:00.0000000 -04:00 How should I revise my code so that it changes the time zone offset from -4:00 to +00:00 in testDateAndTime ?

TimeZoneInfo.ConvertTime from PST to UTC to AEST - off by one hour

若如初见. 提交于 2019-12-20 04:28:16
问题 I convert a string that represents a time in Pacific Time Zone that I am using to create a DateTime object: var pacificDateTime = new DateTime(2016, 11, 16, 15, 0, 0) // 11/16/2016 3:00:00 PM Using that, I create a DateTimeOffset because ultimately it becomes a bit easier to work with. var pacificTimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"); var dateTimeNoKind = new DateTime(pacificDateTime.Ticks, DateTimeKind.Unspecified) var DateTimeOffsetValue = TimeZoneInfo

How to tell if it's British Summer Time

孤街醉人 提交于 2019-12-20 02:46:07
问题 I have the following code, which should return an offset of 60 (to show that in the UK at present, we are in British Summer Time - ie. 60 minutes ahead of GMT): var info = TimeZoneInfo.FindSystemTimeZoneById("Greenwich Standard Time"); DateTimeOffset localServerTime = DateTimeOffset.Now; double off = localServerTime.Offset.TotalMinutes; return off; However, it returns 0. Could anyone please help fix this for me? 回答1: Use TimeZoneInfo.IsDaylightSavingTime Method (DateTimeOffset) to find if it

pandas out of bounds nanosecond timestamp after offset rollforward plus adding a month offset

戏子无情 提交于 2019-12-17 10:53:08
问题 I am confused how pandas blew out of bounds for datetime objects with these lines: import pandas as pd BOMoffset = pd.tseries.offsets.MonthBegin() # here some code sets the all_treatments dataframe and the newrowix, micolix, mocolix counters all_treatments.iloc[newrowix,micolix] = BOMoffset.rollforward(all_treatments.iloc[i,micolix] + pd.tseries.offsets.DateOffset(months = x)) all_treatments.iloc[newrowix,mocolix] = BOMoffset.rollforward(all_treatments.iloc[newrowix,micolix]+ pd.tseries

How to use TimeZoneInfo to get local time during Daylight Saving Time?

亡梦爱人 提交于 2019-12-17 06:25:14
问题 I'm trying to use DateTimeOffset to convey a specific moment in time across any time zone. I can't figure out how to use TimeZoneInfo to deal with daylight saving time. var dt = DateTime.UtcNow; Console.WriteLine(dt.ToLocalTime()); var tz = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time"); var utcOffset = new DateTimeOffset(dt, TimeSpan.Zero); Console.WriteLine(utcOffset.ToOffset(tz.BaseUtcOffset)); This prints out: 6/2/2010 4:37:19 PM 6/2/2010 3:37:19 PM -06:00 I am in the

Saving Datetimeoffset on Azure SQL not working

自作多情 提交于 2019-12-13 17:19:49
问题 I'm having a problem with Azure SQL server, on my local machine I can save a datetimeoffset into the db and the timezone offset is correctly saved like below 2017-03-31 00:00:00.0000000 -05:00 however on azure is losing the timezone offset, my columns are of datetimeoffset type and I'm getting my datetimeoffset using this DateTimeOffset.UtcNow.UtcDateTime or DateTimeOffset.Now but neither way seems to work, is always being saved like the below 2017-03-31 00:00:00.0000000 +00:00 how can I save

GET UTC Date of a past date

霸气de小男生 提交于 2019-12-13 16:57:09
问题 My database have date values saved in GMT time zone in int format. I am trying to convert the date to local timezone, but the issue arises when the date is a past date, For instance in my case offset for date Dec 1, 2012 will be -5 and for June 15, 2010 will be -4 due to daylight savings. I am currently in EST. So i need to know what was the UTC date of a previous date to be able to determine whether -4 or -5 will be the offset for that date. SELECT Test_Number, Last_Test_Date, dateAdd(hour,