timespan

How to parse a TimeSpan value in Newtonsoft JSON

微笑、不失礼 提交于 2019-12-06 05:19:27
问题 I'd like parse JSON string and use the token.Type property to detect values of type JTokenType.TimeSpan . I can't work out how to express the TimeSpan in my input string, everything seems to be interpreted as JTokenType.String. var timeSpanString = TimeSpan.FromHours(1).ToString(); testString = string.Format(@"{{""Value"": ""{0}"" }}", timeSpanString); var statObject = JObject.Parse(testString); JToken token = statObject["Value"]; var tokenValue = token.ToString(); var tokenType = token.Type;

Binding timespan in wpf mvvm, and show only minutes:seconds?

安稳与你 提交于 2019-12-06 03:20:44
问题 I want to be able to set minutes and seconds in a textbox. I now just bind my textbox towards a property, which is a TimeSpan property. So now in my textbox, default is : 00:00:00. This works fine, but i want to be able to just have 00:00. So that the hours are removed. How do i do this? I searched the net but can't find any good solution Thanks! This is my binding: public TimeSpan MaxTime { get { if (this.Examination.MaxTime == 0) return TimeSpan.Zero; else return maxTime; } set { maxTime =

Time span calculation for hours and minutes in C#

六眼飞鱼酱① 提交于 2019-12-05 21:58:04
The final result should display the user the time span between the start hour and the end hour.(e.g. start work at 06:30 AM and finished at 18:30 PM, the result to display should be 12 hours). Now, I have to DateTime parameters; fromTime and toTime Each DateTime parameter have an hour in 24 hour format, and also might have a minutes value of 30 min. What I willing to do is to get the time span between those DateTime parameters. For the hours I used this method: Public TimeSpan GetHourSpan(DateTime fromTime, DateTime toTime) { TimeSpan fromH = TimeSpan.FromHours(fromTime.Hour); TimeSpan toH =

how to achieve timespan to string conversion?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-05 02:08:30
I tried searching here , but it couldn't help me much .. I want to convert time_span to string, I don't want to return the timespan in days .. but only HH:mm:ss. How to achieve that? My sample code is here: String time_span_par = "06:12:40"; String time_str = "18:13:59"; TimeSpan time_span_var = TimeSpan.Parse(time_span_par); TimeSpan time_span = TimeSpan.Parse(time_str); time_span = time_span.Add(time_span_var); string temp = time_span.ToString("HH:mm:ss"); Try using DateTime d = new DateTime(time_span.Ticks); string time = d.ToString("HH:mm:ss"); Kelsey This should work: string temp = string

How to parse a TimeSpan value in Newtonsoft JSON

帅比萌擦擦* 提交于 2019-12-04 12:20:12
I'd like parse JSON string and use the token.Type property to detect values of type JTokenType.TimeSpan . I can't work out how to express the TimeSpan in my input string, everything seems to be interpreted as JTokenType.String. var timeSpanString = TimeSpan.FromHours(1).ToString(); testString = string.Format(@"{{""Value"": ""{0}"" }}", timeSpanString); var statObject = JObject.Parse(testString); JToken token = statObject["Value"]; var tokenValue = token.ToString(); var tokenType = token.Type; // JTokenType.String I even tried: JValue jValue = new JValue("test"); jValue.Value = TimeSpan

c# check if a timespan range is between timespan range and how many hours

我们两清 提交于 2019-12-04 10:01:41
Assuming I have 3 time ranges: 07:00 - 18:00 18:00 - 23:00 23:00 - 07:00 and the code: public class TimeShift { public TimeSpan Start { get; set; } public TimeSpan End { get; set; } } List<TimeShift> shifts = new List<TimeShift>(); How can I check if every item in the list is between the 3 ranges above and how many hours? For example one TimeShift where: Start: 07:00 End: 23:30 then that means 16.5 hours. For the examples above: Range 1: 11 hours Range 2: 5 hours Range 3: 0.5 hours Here is a solution including tests: Calc public class TimeSpacCalculator { public static TimeSpan

Multiply TimeSpan in .NET

风流意气都作罢 提交于 2019-12-04 08:46:44
问题 How do I multiply a TimeSpan object in C#? Assuming the variable duration is a TimeSpan, I would like, for example duration*5 But that gives me an error "operator * cannot be applied to types TimeSpan and int". Here's my current workaround duration+duration+duration+duration+duration But this doesn't extend to non-integer multiples, eg. duration * 3.5 回答1: From this article TimeSpan duration = TimeSpan.FromMinutes(1); duration = TimeSpan.FromTicks(duration.Ticks * 12); Console.WriteLine

Binding timespan in wpf mvvm, and show only minutes:seconds?

北慕城南 提交于 2019-12-04 08:24:36
I want to be able to set minutes and seconds in a textbox. I now just bind my textbox towards a property, which is a TimeSpan property. So now in my textbox, default is : 00:00:00. This works fine, but i want to be able to just have 00:00. So that the hours are removed. How do i do this? I searched the net but can't find any good solution Thanks! This is my binding: public TimeSpan MaxTime { get { if (this.Examination.MaxTime == 0) return TimeSpan.Zero; else return maxTime; } set { maxTime = value; OnPropertyChanged("MaxTime"); TimeSpan x; this.Examination.MaxTime = int.Parse(maxTime

How to get the time-span of all the datetime data in my datagridview

﹥>﹥吖頭↗ 提交于 2019-12-04 07:02:27
问题 The scenario go's like that, above and this; I have a database, which I displayed on my datagridview. I already added the timespan of each row ( timeIn and timeOut ) and stored it on a textbox. Now, I wanted to add and display all the total timespans ( which I already have the timespan of each rows timeIn and timeOut ) of every row using only that textbox. I guess my example is wrong, that should suppose to be all the emp_Code's has only '1' as its values in all three rows. Summary of the

Simplify if else condition using timespan in C#

寵の児 提交于 2019-12-04 06:54:10
I have to create a real time report. For that, I have to write conditions for each and every hour of a given day. In the code below, the condition checks for the current day of week and then check for the current time and based on that a report has to be generated. protected void sample() { TimeSpan zerothHour = new TimeSpan(00, 0, 0); TimeSpan firstHour = new TimeSpan(01, 0, 0); TimeSpan secondHour = new TimeSpan(02, 0, 0); TimeSpan thirdHour = new TimeSpan(03, 0, 0); TimeSpan fourthHour = new TimeSpan(04, 0, 0); TimeSpan fifthHour = new TimeSpan(05, 0, 0); TimeSpan sixthHour = new TimeSpan