timespan

Why those different string formats on TimeSpan on XAML?

馋奶兔 提交于 2019-12-01 15:51:27
问题 I'm going crazy. Can someone explain me why these string formats formatting the same thing are so different? <DataGridTextColumn Header="Max Time" IsReadOnly="True" Binding="{Binding MaxTime, StringFormat=hh\\:mm\\:ss, TargetNullValue=---}"> <DataGridTextColumn Header="Min Time" IsReadOnly="True"> <DataGridTextColumn.Binding> <Binding Path="MinTime" StringFormat="{}{0:hh':'mm':'ss}" TargetNullValue=" --- "/> </DataGridTextColumn.Binding> </DataGridTextColumn> Of course each one do not work on

C# - Difference between two dates?

北慕城南 提交于 2019-12-01 15:49:18
问题 I am trying to calculate the difference between two dates. This is what I'm currently using: int currentyear = DateTime.Now.Year; DateTime now = DateTime.Now; DateTime then = new DateTime(currentyear, 12, 26); TimeSpan diff = now - then; int days = diff.Days; label1.Text = days.ToString() + " Days Until Christmas"; All works fine except it is a day off. I am assuming this is because it does not count anything less than 24 hours a complete day. Is there a way to get it to do so? Thank you. 回答1

Custom format Timespan with String.Format

一曲冷凌霜 提交于 2019-12-01 08:05:59
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. That's simple: String.Format("{0:00} hr {1:00} mn {2:00} sec ", _ Math.Truncate(theTimeSpan.TotalHours), _ theTimeSpan.Minutes, theTimeSpan.Seconds) It's worth becoming familiar with how string formatting works in .NET - it's an important topic. It

TimeSpan to friendly string library (C#)

无人久伴 提交于 2019-12-01 03:06:13
Does anyone know of a good library (or code snippet) for converting a TimeSpan object to a "friendly" string such as: Two years, three months and four days One week and two days (It's for a document expiry system, where the expiry could be anything from a few days to several decades) Just to clarify, say I had a TimeSpan with 7 days, that should print "1 week", 14 days "2 weeks", 366 days "1 year and 1 day", etc etc. Andy_Vulhop Not a fully featured implementation, but it should get you close enough. DateTime dtNow = DateTime.Now; DateTime dtYesterday = DateTime.Now.AddDays(-435.0); TimeSpan

TimeSpan.ToString(“hh:mm”) error [duplicate]

大憨熊 提交于 2019-12-01 02:42:14
This question already has an answer here: Why does DateTime.Now.TimeOfDay.ToString(“HH:mm:ss.ffffff”) throw FormatException? 2 answers Why I got an error when I want to get the string of a TimeSpan with a custom format. DateTime.Now.TimeOfDay.ToString("hh:mm"); // Error: Input string was not in a correct format. DateTime.Now.TimeOfDay.ToString(@"hh\:mm\:ss") Documentation According to MSDN TimeOfDay is a TimeSpan. And in the examples of TimeSpan.ToString you see that the : needs to be escaped. hh\:mm\:ss: 03:00:00 This is also explained on Microsoft's page Custom TimeSpan Format Strings The

Client side validation of a timespan on asp.net mvc 3

老子叫甜甜 提交于 2019-12-01 00:04:26
I need to receive some time information in the format "hh:mm" ( no seconds ). The property is defined like this: [DataType(DataType.Time), DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = @"{0:hh\:mm}")] public TimeSpan SomeTimeProperty { get; set; } The server side validation works as expected. However, I can't get the client side validation to work as no client-side validation rules are generated. How can I make it work? I am afraid you will need to go the long route and create a Custom validator attribute for it. public class TimeSpanValidationAttribute : ValidationAttribute,

How can a Timespan-Day last only for 8 Hours?

江枫思渺然 提交于 2019-11-30 22:09:33
I have saved a duration in minutes and want to have an output "1 day 5 hours 30 minutes". Currently i add the minutes to a Timespan and do something like this: TimeSpan ts = new TimeSpan(0,0,1800, 0); Response.Write(ts.Days + "day(s) " + ts.Hours + " hour(s)" + ts.Minutes + " minutes"); But now i am only interested in the working-hours of a day. So when the duration of the TimeSpan is 27 Hours it should not create the output "1 Day 3 Hours". I want to have "3 Days 3 Hours". Is there maybe an easy way to do that with the Timespan object? Is it possible to change the default behaviour of the

Client side validation of a timespan on asp.net mvc 3

*爱你&永不变心* 提交于 2019-11-30 18:23:36
问题 I need to receive some time information in the format "hh:mm" ( no seconds ). The property is defined like this: [DataType(DataType.Time), DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = @"{0:hh\:mm}")] public TimeSpan SomeTimeProperty { get; set; } The server side validation works as expected. However, I can't get the client side validation to work as no client-side validation rules are generated. How can I make it work? 回答1: I am afraid you will need to go the long route and

How can a Timespan-Day last only for 8 Hours?

≯℡__Kan透↙ 提交于 2019-11-30 17:43:41
问题 I have saved a duration in minutes and want to have an output "1 day 5 hours 30 minutes". Currently i add the minutes to a Timespan and do something like this: TimeSpan ts = new TimeSpan(0,0,1800, 0); Response.Write(ts.Days + "day(s) " + ts.Hours + " hour(s)" + ts.Minutes + " minutes"); But now i am only interested in the working-hours of a day. So when the duration of the TimeSpan is 27 Hours it should not create the output "1 Day 3 Hours". I want to have "3 Days 3 Hours". Is there maybe an

C# How to get Audio Decibel values with time span

一曲冷凌霜 提交于 2019-11-30 16:05:01
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, With NAudio you can use the WaveFileReader and Mp3FileReader classes to get access to the sample data within the file as a byte array. Then you would need to read through the file and get the sample values (e.g. for 16