timespan

How can I parse timespan string to hour, minutes?

这一生的挚爱 提交于 2020-01-05 09:46:32
问题 I have a string "P18DT5H2M3S" which means: 18 days, 5 hours, 2 minutes, 3 seconds. I have to parse this string to hour and minute. Should I use regex or split or substr etc...? (regarding to this How can I convert come string timespan variable from Wcf to hours and minutes?) 回答1: You can use whatever you want. Following is the example using split method with regex. var res = "P18DT5H2M3S"; var tokens = res.split(/[A-Z]+/); //var str = "D:"+token[1]+" H:"+tokens[2]+" M:"+tokens[3]+" S:"+tokens

Calculating days from TimeSpan hours

一笑奈何 提交于 2020-01-04 05:23:07
问题 I have 1 single text box which a user will enter the number of hours. At present, if they enter 26 hours, we get an error because of the TimeSpan's HH limit. This value is going to get stored in a SQL Server 2008 Time(7) field. How can I get it to recognize more than 23 hours? It is not an option to store it as a decimal because another section of the program requires this field to be a time(7) field. TimeSpan estiamtedHours; private void btnSave_Click(object sender, EventArgs e) {

Find time in milliseconds using PowerShell?

萝らか妹 提交于 2020-01-03 06:48:08
问题 How can I find the time in milliseconds using PowerShell? 回答1: In PowerShell you can cast a time value to a timespan and call the TotalMilliseconds method: ([TimeSpan]"00:05:00").TotalMilliseconds # Returns 300000 ([TimeSpan] (Get-Date).ToShortTimeString()).TotalMilliseconds # Returns total milliseconds from 00:00:00 till now 回答2: You can get the full date with milliseconds with the following: Get-Date -Format HH:mm:ss.fff 回答3: The question suggests finding a given datetime in milliseconds

What is Best way to calculate time span

不问归期 提交于 2020-01-01 05:46:06
问题 In my c# program, my requirement is to calculate a timespan for business logic execution that is inside a foreach loop I have to store time span. I am using following code for (int i = 0; i < 100; i++) { DateTime start= DateTime.Now; // Business logic DateTime end= DateTime.Now; TimeSpan time = start.Subtract(end); // Save timespan in log file } Please correct me whether I am using right code, or do I need to modify for better performance and result. 回答1: You should use a Stopwatch. The

What is the most intuitive, usable way of entering a time of day or a duration?

自作多情 提交于 2020-01-01 05:36:11
问题 I'm building a line-of-business application in Silverlight and need to get the user to edit two .NET TimeSpan values. One is a time of day (relative to midnight) and the other is a duration. Currently I'm using two TextBoxes, formatted as hh:mm. This is pretty straightforward, but it could definitely be improved. I've observed people using the application and while some have no problem quickly entering times, other people struggle. Given that I'm working in Silverlight2, what would you see as

Handle negative time spans

99封情书 提交于 2019-12-30 02:33:05
问题 In my output of a grid, I calculate a TimeSpan and take its TotalHours . e.g. (Eval("WorkedHours") - Eval("BadgedHours")).TotalHours The goal is to show the TotalHours as 39:44 , so I need to convert the value from 7.5 to 07:30 . This is no problem... unless it's negative! I can create a TimeSpan object from Hours with TimeSpan.FromHours( (Eval("WorkedHours") - Eval("BadgedHours")).TotalHours) If it's negative, I can't convert it to a DateTime to use the .ToString("HH:mm") method, and the

How convert TimeSpan to 24 hours and minutes String?

社会主义新天地 提交于 2019-12-30 01:39:59
问题 I use this code for converting Timespan to String (for ex: 14:53) : myTimeSpan.ToString("hh:mm"); but this error occurs: Input string was not in a correct format What is the proper way to do this? 回答1: myTimeSpan.ToString(@"hh\:mm") Custom TimeSpan Format Strings The custom TimeSpan format specifiers do not include placeholder separator symbols, such as the symbols that separate days from hours, hours from minutes, or seconds from fractional seconds. Instead, these symbols must be included in

Sum of TimeSpans in C#

南楼画角 提交于 2019-12-27 23:35:35
问题 I have a collection of objects that include a TimeSpan variable: MyObject { TimeSpan TheDuration { get; set; } } I want to use LINQ to sum those times. Of course, (from r in MyCollection select r.TheDuration).Sum(); doesn't work! I'm thinking of changing the datatype of TheDuration to an int and then summing it and converting the sum to a TimeSpan. That will be messy because each TheDuration in my collection is used in as a timespan somewhere else. Any suggestion on this summation? 回答1:

How to get difference between times only

旧城冷巷雨未停 提交于 2019-12-25 05:19:19
问题 I want only time difference between two values, it gives the wrong value when I cross 12 hours. ex: 6:00 AM and select 7:00 PM then gives result as 660 minute instead of 780. it works till I select time between 12 hours range. Please help me to resolve this stuff. Dim sDateStart As DateTime = Convert.ToDateTime(CType(cboStartHours.SelectedItem, ListItem).ItemText & ":" _ & CType(cboStartMins.SelectedItem, ListItem).ItemText & ":00 " _ & CType(cboStartAMPM.SelectedItem, ListItem).ItemText) Dim

getting timestamp in php

二次信任 提交于 2019-12-25 02:22:30
问题 How can I get the timestamp of a desired hour? The hour is in a variable that the user set. 回答1: $hr = 10; echo strtotime("today +$hr hours"); 回答2: You can use mktime() function to build timestamp of any datetime. 来源: https://stackoverflow.com/questions/4772953/getting-timestamp-in-php