timespan

Peek MSMQ message with unlimited timeout

ε祈祈猫儿з 提交于 2019-12-11 09:09:53
问题 I am writing an application that peeks message from Microsoft Message Queue (MSMQ). I want my application peeks MSMQ messages in turn(from the first message to the last message ). After peeks the last message completly, the main thread will be blocked until MSMQ have a new message arrive. I've already used MessageQueue.Peek(TimeSpan, Cursor, PeekAction) Method with TimeSpan=MessageQueue.InfiniteTimeout and have a problem: MessageQueue.InfiniteTimeout value approximates 49 days but I want my

EF, How to save/retrieve TimeSpan as other data type?

折月煮酒 提交于 2019-12-11 08:35:49
问题 SQLCe doesn't support TimeSpan, so I need to save this in some other way. Is it possible to define somewhere a default conversion, like in the DbContext, or would I need to handle this manually in the repositories? I don't like to change my entity classes just because of this. Btw, I only save TimeSpan of < 24h. Example would be great if there are some neat tricks. 回答1: I know you say you don't want to modify your entities, but if you're using code first this would be pretty simple to do by

Timespan - Check for weekday and time of day in mysql

Deadly 提交于 2019-12-11 06:46:49
问题 I need to have a database with different rates at different time of day and on different weekdays. For example: Between 10:00 and 16:00 monday to friday I have one rate. Between 16:00 and 10:00 monday to friday I have another. And on the weekends there is another rate. The problem is when the time goes over midnight. I have looked around for a solution. I have found this thread that I thought would work for me but it doesn't. At least I can't get it to work as I want it to. Dealing with times

Given a list of dates, how do I get the nearest date in the past to today and the nearest date in the future to today in VB.NET

爱⌒轻易说出口 提交于 2019-12-11 05:50:38
问题 I am currently using the function below to return the nearest date from a list of dates to a date(today). My problem is, the function returns the closest date regardless of it being the past or the future of todays date. How can I change this code so there is an option to return the nearest date AFTER today and the nearest date BEFORE today? It's confusing the hell out of me. Thanks a lot for your input. Function GetNearestDate(ByVal source As IEnumerable(Of DateTime), ByVal target As

MultiBinding StringFormat of TimeSpan

五迷三道 提交于 2019-12-11 05:22:53
问题 I cannot for the life of me get this to work. I need to display hh:mm from a pair of timespan objects in a textblock and it is just not working. This is what I have so far: <TextBlock> <TextBlock.Text> <MultiBinding StringFormat="{}From {0:hh\\:mm} to {1:hh\\:mm}"> <Binding Path="StartTime"/> <Binding Path="EndTime"/> </MultiBinding> </TextBlock.Text> </TextBlock> The text block shows up blank. I've also tried the following with the same results: <TextBlock> <TextBlock.Text> <MultiBinding

DateTime range issue when time passes midnight

♀尐吖头ヾ 提交于 2019-12-11 04:43:47
问题 I'm doing an application for work and I've just ran into a brickwall. We have 3 shifts, 06:00-13:36, 13:36-23:00 and 23:00-06:00. I have two labels, one to display shift start time and the other shift end time using the following code: Dim StartTimeN As Date = DateTime.Now.AddDays(-1).ToShortDateString & " 23:01" Dim EndTimeN As Date = DateTime.Now.ToShortDateString & " 06:00" Dim StartTimeF As Date = DateTime.Now.ToShortDateString & " 06:01" Dim EndTimeF As Date = DateTime.Now

Convert string to TimeSpan

我是研究僧i 提交于 2019-12-11 04:17:10
问题 I need to convert this into a timespan: 8 8.3 8.15 When I do it like so: DateTime s = booking.TourStartDate.Add(TimeSpan.Parse(booking.TourStartTime.Replace(".", ":"))); It will end up adding say '10' (10am) into days rather than the time that it is, albeit in a stupid format that it is. 回答1: You could do it the straightforward way: static Regex myTimePattern = new Regex( @"^(\d+)(\.(\d+))?$") ; static TimeSpan MyString2Timespan( string s ) { if ( s == null ) throw new ArgumentNullException(

DataView RowFilter with TimeSpan DataType

自闭症网瘾萝莉.ら 提交于 2019-12-11 03:13:43
问题 I try to use the DataView RowFilter for a column with DataType "TimeSpan" as following: dv.RowFilter = ("Convert([time],System.String) LIKE '17:12:00'") I've found that the search Parameter "%17% or %12% , for the double Zeros i have to use a single one: %0%, works fine, now im not sure about the Convert(timespan, System.String) Format... . I know that the TimeSpan have a Special Format like (17,12,0) or {17}{12}{0} but as a not specified convert to string it should be: hh:mm:ss like timespan

Formatting a TimeSpan to look like a time zone offset

给你一囗甜甜゛ 提交于 2019-12-11 03:06:41
问题 How can I format a TimeSpan object to look like a time zone offset, like this: +0700 or -0600 I'm using GetUtcOffset to get an offset, and its working, but its returning a TimeSpan object. 回答1: If you're using .Net 4.0 or above, you can use the ToString method on timespan with the hh and mm specifier (not sure if it will display the + and - signs though): TimeSpan span = new TimeSpan(7, 0, 0); Console.WriteLine(span.ToString("hhmm")); If not, you can just format the Hours and Minutes

Average time from a list of start end times in linq to sql

家住魔仙堡 提交于 2019-12-11 01:47:58
问题 I have a list of *startTime (datetime) *endTime (datetime) and need to work out the average time for everything in the list. So I am guessing I need something like long averageTime = Convert.ToInt64(listOfStartEndTimes.Average(timeSpan => timeSpan.Ticks)) Any ideas? 回答1: long averageTime = listOfStartEndTimes .Select(se => se.End - se.Start) .Average(t => t.Ticks); Or alternatively, with a slightly lower resolution (unix epoch date instead): long averageTime = listOfStartEndTimes .Select(se =