Sum of TimeSpans in C#

Unfortunately, there isn’t a an overload of Sum that accepts an IEnumerable<TimeSpan>. Additionally, there’s no current way of specifying operator-based generic constraints for type-parameters, so even though TimeSpan is “natively” summable, that fact can’t be picked up easily by generic code. One option would be to, as you say, sum up an integral-type equivalent to … Read more

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

You can use the Calendar class in order to check. For example: try { String string1 = “20:11:13”; Date time1 = new SimpleDateFormat(“HH:mm:ss”).parse(string1); Calendar calendar1 = Calendar.getInstance(); calendar1.setTime(time1); calendar1.add(Calendar.DATE, 1); String string2 = “14:49:00”; Date time2 = new SimpleDateFormat(“HH:mm:ss”).parse(string2); Calendar calendar2 = Calendar.getInstance(); calendar2.setTime(time2); calendar2.add(Calendar.DATE, 1); String someRandomTime = “01:00:00”; Date d = new SimpleDateFormat(“HH:mm:ss”).parse(someRandomTime); … Read more

Environment.TickCount vs DateTime.Now

Environment.TickCount is based on GetTickCount() WinAPI function. It’s in milliseconds But the actual precision of it is about 15.6 ms. So you can’t measure shorter time intervals (or you’ll get 0) Note: The returned value is Int32, so this counter rolls over each ~49.7 days. You shouldn’t use it to measure such long intervals. DateTime.Ticks … Read more

How to get the latest and oldest record in mongoose.js (or just the timespan between them)

Mongoose 3.x is complaining about the [] parameter in your findOne calls as the array format is no longer supported for the parameter that selects the fields to include. Try this instead to find the newest: Tweet.findOne({}, {}, { sort: { ‘created_at’ : -1 } }, function(err, post) { console.log( post ); }); Change the … Read more

Convert milliseconds to human readable time lapse

You can use TimeSpan class, something like this: TimeSpan t = TimeSpan.FromMilliseconds(ms); string answer = string.Format(“{0:D2}h:{1:D2}m:{2:D2}s:{3:D3}ms”, t.Hours, t.Minutes, t.Seconds, t.Milliseconds); It’s quite similar as this thread I’ve just found: What is the best way to convert seconds into (Hour:Minutes:Seconds:Milliseconds) time?

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)