timespan

How to deal with Rounding-off TimeSpan?

一世执手 提交于 2019-11-30 15:32:23
问题 I take the difference between two DateTime fields, and store it in a TimeSpan variable, Now I have to round-off the TimeSpan by the following rules: if the minutes in TimeSpan is less than 30 then Minutes and Seconds must be set to zero, if the minutes in TimeSpan is equal to or greater than 30 then hours must be incremented by 1 and Minutes and Seconds must be set to zero. TimeSpan can also be a negative value, so in that case I need to preserve the sign.. I could be able to achieve the

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

别说谁变了你拦得住时间么 提交于 2019-11-30 10:38:10
问题 Basic problem I have a bunch of records and I need to get latest (most recent) and the oldest (least recent). When googling I found this topic where I saw a couple of queries: // option 1 Tweet.findOne({}, [], { $orderby : { 'created_at' : -1 } }, function(err, post) { console.log( post ); }); // option 2 Tweet.find({}, [], {sort:[['arrival',-1]]}, function(err, post) { console.log( post ); }); Unfortunatly they both error: TypeError: Invalid select() argument. Must be a string or object. The

AM/PM to TimeSpan

限于喜欢 提交于 2019-11-30 08:59:15
问题 I want to achieve the converse of this, that is, I want to convert a string with format hh:mm tt to a TimeSpan with zeroed seconds. For example, 09:45 pm is converted to 21:45:00 . 回答1: The simplest approach would probably be to parse it as a DateTime using DateTime.ParseExact , and then use the TimeOfDay to exact the TimeSpan . DateTime dateTime = DateTime.ParseExact(text, "hh:mm tt", CultureInfo.InvariantCulture); TimeSpan span = dateTime.TimeOfDay; It's odd to see a leading 0 on a number

Handle negative time spans

烂漫一生 提交于 2019-11-30 08:07:31
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 TimeSpan object does not support the format string. Jared Isn't there a TimeSpan.Duration method? I think

Datetime.now as TimeSpan value?

自古美人都是妖i 提交于 2019-11-30 07:53:35
问题 I need the current Datetime minus myDate1 in seconds. DateTime myDate1 = new DateTime(1970, 1, 9, 0, 0, 00); DateTime myDate2 = DateTime.Now; TimeSpan myDateResult = new TimeSpan(); myDateResult = myDate2 - myDate1; . . I tried different ways to calculate but to no effect. TimeSpan mySpan = new TimeSpan(myDate2.Day, myDate2.Hour, myDate2.Minute, myDate2.Second); . The way it's calculated doesn't matter, the output should just be the difference these to values in seconds. 回答1: Your code is

How to Convert ISO 8601 Duration to TimeSpan in VB.Net?

荒凉一梦 提交于 2019-11-30 06:54:10
Is there a standard library method that converts a string that has duration in the standard ISO 8601 Duration (also used in XSD for its duration type) format into the .NET TimeSpan object? For example, P0DT1H0M0S which represents a duration of one hour, is converted into New TimeSpan(0,1,0,0,0). A Reverse converter does exist which works as follows: Xml.XmlConvert.ToString(New TimeSpan(0,1,0,0,0)) The above expression will return P0DT1H0M0S. This will convert from xs:duration to TimeSpan: System.Xml.XmlConvert.ToTimeSpan("P0DT1H0M0S") See http://msdn.microsoft.com/en-us/library/system.xml

Formatting MVC model TimeSpan field

家住魔仙堡 提交于 2019-11-30 04:52:47
I have a MVC page containing a few timepickers. These are stored in a list of objects in the model as nullable TimeSpan . The problem is that I get the timespans printed with seconds into the input fields. Is there some way to format these model properties so that I get the timespans printed in some other way (like 7:00 , instead of 07:00:00 )? Needless to say, my "suggestion" of [DisplayFormat...] didn't work. At least not the way I hoped. The input fields are defined like this: @Html.TextBoxFor(x => x.Shifts[i].Start) The relevant part of the model looks like: public class Workshift {

Subtracting two dates

守給你的承諾、 提交于 2019-11-30 04:43:51
I have two calendars and each return a DateTime from calendar.SelectedDate. How do I go about subtracting the two selected dates from each other, giving me the amount of days between the two selections? There is a calendar.Subtract() but it needs a TimeSpan instead of DateTime. You can use someDateTime.Subtract(otherDateTime) , this returns a TimeSpan which has a TotalDays property. Jon Skeet Just use: TimeSpan difference = end - start; double days = difference.TotalDays; Note that if you want to treat them as dates you should probably use TimeSpan difference = end.Date - start.Date; int days

C# How to get Audio Decibel values with time span

我的未来我决定 提交于 2019-11-29 23:48:57
问题 how can I get Decibel values of a wav/mp3 file I have every 1 second? using any audio library that works with C#.. something like: Time: 0, DB: 0.213623 Time: 1, DB: 0.2692261 Time: 2, DB: 0.2355957 Time: 3, DB: 0.2363281 Time: 4, DB: 0.3799744 Time: 5, DB: 0.3580322 Time: 6, DB: 0.1331177 Time: 7, DB: 0.3091431 Time: 8, DB: 0.2984009 I'd really appreciate your help :) regards, 回答1: With NAudio you can use the WaveFileReader and Mp3FileReader classes to get access to the sample data within

subtract 2 datetime fields to get the days left difference

送分小仙女□ 提交于 2019-11-29 22:56:24
Would appreciate it if anyone can help me figure out to substract 2 datetime fields to get the days left difference. Maxim Zaslavsky This is very easy to do with C#. For comparing DateTimes, we have a class called TimeSpan . The TimeSpan structure, in this case, would be defined as the difference between your two datetimes . Let's say that your DateTimes are called start and end. DateTime start = new DateTime(2009, 6, 14); DateTime end = new DateTime(2009, 12, 14); We have established our DateTimes to June 14, 2009 and December 14, 2009. Now, let's find the difference between the two. To do