timespan

How many specific days within a date range in Javascript

一笑奈何 提交于 2019-12-24 03:38:26
问题 I have two dates. One is starting date and another is ending date. I want to calculate how many Saturdays, Mondays and Wednesdays falls within the date range? How can I solve it? I saw several tutorial but they are only counting the dates within date range. Thanks in advance. I am using the following code to calculate only business days but I need only how many saturdays, mondays and wednesdays falls within the date range. <!DOCTYPE html> <html> <head> <meta charset=utf-8 /> <title>JS Bin<

TimeSpan.ParseExact giving error

半世苍凉 提交于 2019-12-23 18:31:16
问题 I created a TimeSpan this way TimeSpan ts = new Timespan(); // Do some addition and subtraction on it Then I am saving it to a file using this string.Format("{0}:{1}:{2}:{3}", ts.Hours, ts.Minutes, ts.Seconds, ts.MilliSeconds); Various values returned from it are like this 0:0:4:410 0:0:1:425 0:0:1:802 0:0:1:509 0:0:1:674 0:0:1:628 0:0:2:76 How to convert it back to TimeSpan. I am using TimeSpan.ParseExact("0:0:4:410", "h:m:s:fff", null); but it is giving me error Input String is not in

Getting the total hours in a TimeSpan

两盒软妹~` 提交于 2019-12-23 16:47:09
问题 How can I subtract two dates and get the total hours of the TimeSpan object that is returned? For example, if the TimeSpan is 2 days, the total hours are 48. 回答1: Then you want the TotalHours property of the TimeSpan object: DateTime today = DateTime.Today; DateTime twoDaysAgo = today.AddDays(-2.0); // returns 48.0 double totalHours = (today - twoDaysAgo).TotalHours; 回答2: I did it this way: int day = Tempo.Days; int Hours = Tempo.Hours; if (day > 0) { for (int i = 0; i < day; i++) { Hours +=

How to convert string offset to timespan in c#

蓝咒 提交于 2019-12-23 10:18:23
问题 I'm trying to convert the convert time to the user's time zone, but I don't have the windows time zone string such as "Pacific Standard Time". All I have is a string offset such as "-07:00". Looks like I need to create a timespan. Is the only way to parse this string manually?. Seems like there should be a way to convert a time using a string offset, but maybe I am missing something. I have this but it requires the timezone. I'm trying to modify it to use the offset instead, but you can see

Formatting a negative TimeSpan

给你一囗甜甜゛ 提交于 2019-12-23 06:47:47
问题 I'm doing some math with the Timespans in .Net, and occasionally the sum results in a negative Timespan. When I display the result I am having trouble formatting it to include the negative indicator. Dim ts as New Timespan(-10,0,0) ts.ToString() This will display "-10:00:00", which is good but I don't want to show the seconds so tried this. ts.ToString("hh\:mm") This returns "10:00" and has dropped the "-" from the front which is the crux of the issue. My current solution is this: If(ts <

Timespan-Regex with Days-Portion

China☆狼群 提交于 2019-12-23 01:52:57
问题 I've just tried several hundreds (if not thousands...) of RegEx's available to get what I want... But none of them worked. I'm simply looking for a Regular expression, that represents a TimeSpan days.hours:minutes:seconds : 7.00:00:00 would represent "7 Days" This one sadly doesn't work: (\d\d).(\d\d):(([0-6][0])|([0-5][0-9])):(([0-6][0])|([0-5][1-9])) 回答1: That's because your Regex pattern is expecting 2 digits for days and you only have 1 digit. Just make the first digit optional with ? (\d

Time span calculation for hours and minutes in C#

拜拜、爱过 提交于 2019-12-22 10:53:09
问题 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

Get Ticks per second and convert to String value?

喜欢而已 提交于 2019-12-22 05:33:46
问题 How do I get number of ticks per second of DateTime.UtcNow and convert it to a String value? BAD QUESTION: try again Get ten millionths of a second 回答1: A particular value of DateTime doesn't have a "ticks per second" associated with it; ticks are ticks no matter which DateTime they're in. Ticks are 100 nanoseconds long, so there are 10,000,000 of them per second. Now to get that as a string is as simple as the string literal "10000000"... although in general you would obtain a number and

C# Method to sum hh:mm data ???

夙愿已清 提交于 2019-12-19 19:54:33
问题 I want a method that will sum data that is string in the format hh:mm (time hours and minutes) 0:15 + 0:15 = 0:30 回答1: Convert the strings to TimeSpan s and then call the .Add method. TimeSpan s1 = TimeSpan.Parse("0:15"); TimeSpan s2 = TimeSpan.Parse("0:45"); TimeSpan s3 = s1 + s2; // not tested; should work. Ref: http://msdn.microsoft.com/en-us/library/system.timespan.aspx 来源: https://stackoverflow.com/questions/2871557/c-sharp-method-to-sum-hhmm-data

Custom format Timespan with String.Format

为君一笑 提交于 2019-12-19 09:42:17
问题 I want to format the Timespan to have format like this 49 hr 34 mn 20 sec I used the String format below: String.Format("{0:00}:{1:00}:{2:00}", theTimeSpan.TotalHours, theTimeSpan.Minutes, theTimeSpan.Seconds) It formats the Timespan to this format 49:34:20. How can I add hr mn sec to the String.Format above? or there's another easy way? Thank you. 回答1: That's simple: String.Format("{0:00} hr {1:00} mn {2:00} sec ", _ Math.Truncate(theTimeSpan.TotalHours), _ theTimeSpan.Minutes, theTimeSpan