timespan

Can you round a .NET TimeSpan object?

試著忘記壹切 提交于 2019-12-17 10:49:29
问题 Can you round a .NET TimeSpan object? I have a Timespan value of: 00:00:00.6193789 Is there a simple way to keep it a TimeSpan object but round it to something like 00:00:00.62? 回答1: Sorry, guys, but both the question and the popular answer so far are wrong :-) The question is wrong because Tyndall asks for a way to round but shows an example of truncation . Will Dean's answer is wrong because it also addresses truncation rather than rounding . (I suppose one could argue the answer is right

Work with a time span in Javascript

て烟熏妆下的殇ゞ 提交于 2019-12-17 10:44:59
问题 Using Date.js already, but can also use another library if necessary. Not sure what is the best way to work with time deltas. Specifically, I want to display the time that has elapsed between now and a past date-time. So I need to do something like this: var elapsed_time = new Date() - pastDate; pastDate.toString('days-hours-minutes-seconds'); Gotten it to mostly work using Date.js, but the problem is now I'm working with a Date object and not a timespan, so what should be an 23 hour time

Getting time span between two times in C#?

倖福魔咒の 提交于 2019-12-17 07:17:41
问题 I have two textboxes. One for a clock in time and one for clock out. The times will be put in this format: Hours:Minutes Lets say I have clocked in at 7:00 AM and clocked out at 2:00 PM. With my current code, I get a difference of 2 hours, but it should be 7 hours. How would I do that in C#. I was going to convert to the 24 hour, by letting the user select AM or PM, but I got confused. So, basically, how would I calculate the difference of hours between the two times? I tried this, but got 2

Why does TimeSpan.ParseExact not work

廉价感情. 提交于 2019-12-17 06:49:18
问题 This is a bit wierd. Parsing a text field with a valid timespan fails if I try to be precise! const string tmp = "17:23:24"; //works var t1 = TimeSpan.Parse(tmp); //fails var t2 = TimeSpan.ParseExact(tmp, "hh:mm:ss", System.Globalization.CultureInfo.InvariantCulture); The second parse fails with an exception "Input string was not in a correct format." from DateTime. 回答1: From the documentation: Any other unescaped character in a format string, including a white-space character, is interpreted

Check if a given time lies between two times regardless of date

别等时光非礼了梦想. 提交于 2019-12-17 03:35:21
问题 I have timespans: String time1 = 01:00:00 String time2 = 05:00:00 I want to check if time1 and time2 both lies between 20:11:13 and 14:49:00 . Actually, 01:00:00 is greater than 20:11:13 and less than 14:49:00 considering 20:11:13 is always less than 14:49:00 . This is given prerequisite. So what I want is, 20:11:13 < 01:00:00 < 14:49:00 . So I need something like that: public void getTimeSpans() { boolean firstTime = false, secondTime = false; if(time1 > "20:11:13" && time1 < "14:49:00") {

What is the correct SQL type to store a .Net Timespan with values > 24:00:00?

陌路散爱 提交于 2019-12-17 01:04:32
问题 I am trying to store a .Net TimeSpan in SQL server 2008 R2. EF Code First seems to be suggesting it should be stored as a Time(7) in SQL. However TimeSpan in .Net can handle longer periods than 24 hours. What is the best way to handle storing .Net TimeSpan in SQL server? 回答1: I'd store it in the database as a BIGINT and I'd store the number of ticks (eg. TimeSpan.Ticks property). That way, if I wanted to get a TimeSpan object when I retrieve it, I could just do TimeSpan.FromTicks(value) which

What is the correct SQL type to store a .Net Timespan with values > 24:00:00?

烂漫一生 提交于 2019-12-17 01:01:35
问题 I am trying to store a .Net TimeSpan in SQL server 2008 R2. EF Code First seems to be suggesting it should be stored as a Time(7) in SQL. However TimeSpan in .Net can handle longer periods than 24 hours. What is the best way to handle storing .Net TimeSpan in SQL server? 回答1: I'd store it in the database as a BIGINT and I'd store the number of ticks (eg. TimeSpan.Ticks property). That way, if I wanted to get a TimeSpan object when I retrieve it, I could just do TimeSpan.FromTicks(value) which

Taking Screenshot after 1 minute [closed]

你离开我真会死。 提交于 2019-12-13 22:03:58
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . I have two questions: 1. How can I take screenshot after every 1 min, when a key is pressed E.g. 10:00: -> key pressed -> Img1 10:01: -> key pressed -> Img2 10:02: -> key pressed -> Img3 2. How can I iterate the image chain assuming my program runs for 5-10 mins string ImgPath = @

Calculate the number of Calendar Months between two dates [duplicate]

穿精又带淫゛_ 提交于 2019-12-13 01:50:51
问题 This question already has answers here : Difference in months between two dates (38 answers) Closed 5 years ago . I am developing a interest calculator in C#. I need to know the number of days between 2 dates So, I am calculating something like this : DateTime dt1 = DateTime.ParseExact(DateTime.Now.Date.ToString("dd-MM-yy"), "dd-MM-yy", CultureInfo.InvariantCulture).Date; DateTime dt2 = DateTime.ParseExact(Duration, "dd-MM-yy", CultureInfo.InvariantCulture).Date; Double no_days = (dt1 - dt2)

MySQL: a timespan available within consecutive times

廉价感情. 提交于 2019-12-12 23:15:21
问题 I have a table with consecutive times and dates for an agenda. ID date begin_time end_time 1 05-02-15 19:00:00 19:05:00 2 05-02-15 19:05:00 19:10:00 3 05-02-15 19:10:00 19:15:00 4 05-02-15 19:15:00 19:20:00 5 05-02-15 19:20:00 19:25:00 6 05-02-15 19:25:00 19:30:00 7 05-02-15 19:30:00 19:35:00 8 05-02-15 19:35:00 19:40:00 9 06-02-15 19:00:00 19:05:00 10 06-02-15 19:05:00 19:10:00 11 06-02-15 19:10:00 19:15:00 12 13 14 06-02-15 19:25:00 19:30:00 15 06-02-15 19:30:00 19:35:00 16 06-02-15 19:35