timespan

Convert eg. 2012-05-25 to seconds since January 1 1970

北战南征 提交于 2019-12-03 07:23:29
I have a database where I save time as time() from php, which is seconds since 1 jan 1970 . Is there any way I can convert, for example 2012-12-12 to seconds since 1 jan 1970 ? I want to do like: SELECT * FROM Table WHERE date > '2012-11-30' AND date < '2012-12-30' Is this even possible? (I would like to do it without any php date()) DATEDIFF is going to be your friend here: select datediff(s, '1970-01-01', '2012-12-12') as SecondsSinceEpoch Note that because datediff returns an int, the maximum datetime you can compare (using seconds) with Jan 1st, 1970 is 2038-01-19 03:14:07 . 来源: https:/

Convert milliseconds to human readable time lapse

你说的曾经没有我的故事 提交于 2019-12-03 06:11:52
问题 I would like to format some commands execution times in a human readable format, for example: 3 -> 3ms 1100 -> 1s 100ms 62000 -> 1m 2s etc .. Taking into account days, hours, minutes, seconds, ... Is it possible using C# ? 回答1: 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

Opening Hours Database Design

梦想的初衷 提交于 2019-12-03 03:52:58
We are currently developing an application in which multiple entities have associated opening hours. Opening hours may span multiple days, or may be contained within a single day. Ex. Opens Monday at 6:00 and closes at Friday at 18:00. Or Opens Monday at 06:00 and closes Monday at 15:00. Also, an entity may have multiple sets of opening hours per day. So far, the best design I have found, is to define an opening hour to consist of the following: StartDay, StartTime, EndDay and EndTime. This design allows for all the needed flexibility. However, data integrity becomes an issue. I cannot seem to

How long is a .NET DateTime/TimeSpan tick?

[亡魂溺海] 提交于 2019-12-03 00:56:35
How long is a .NET DateTime/TimeSpan tick? Although currently a tick is 100 nanoseconds, it is best not to rely on this as an absolute. Rather, use ' TimeSpan.TicksPerSecond ' (or any of the other TicksPerXxx member values) Jason Kresowaty The tick is the unit of granularity for the .NET DateTime and TimeSpan value types. It has the following common conversions: 1 tick = 100 nanoseconds = 0.1 microseconds = 0.0001 milliseconds = 0.0000001 seconds To quote MSDN : The smallest unit of time is the tick, which is equal to 100 nanoseconds . Metrology fail. utunga Note that, although the theoretical

Multiply TimeSpan in .NET

[亡魂溺海] 提交于 2019-12-03 00:52:34
How do I multiply a TimeSpan object in C#? Assuming the variable duration is a TimeSpan , I would like, for example duration*5 But that gives me an error "operator * cannot be applied to types TimeSpan and int". Here's my current workaround duration+duration+duration+duration+duration But this doesn't extend to non-integer multiples, eg. duration * 3.5 From this article TimeSpan duration = TimeSpan.FromMinutes(1); duration = TimeSpan.FromTicks(duration.Ticks * 12); Console.WriteLine(duration); For those wishing to copy and paste: namespace Utility { public static class TimeSpanExtension { ///

Convert milliseconds to human readable time lapse

人盡茶涼 提交于 2019-12-02 18:42:44
I would like to format some commands execution times in a human readable format, for example: 3 -> 3ms 1100 -> 1s 100ms 62000 -> 1m 2s etc .. Taking into account days, hours, minutes, seconds, ... Is it possible using C# ? walther 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? I know this is old, but

How to get the time-span of all the datetime data in my datagridview

北战南征 提交于 2019-12-02 13:02:34
The scenario go's like that, above and this; I have a database, which I displayed on my datagridview. I already added the timespan of each row ( timeIn and timeOut ) and stored it on a textbox. Now, I wanted to add and display all the total timespans ( which I already have the timespan of each rows timeIn and timeOut ) of every row using only that textbox. I guess my example is wrong, that should suppose to be all the emp_Code's has only '1' as its values in all three rows. Summary of the question: How can I get the timespan of row1 + timespan of row2 + timespan of row 3 and display it on a

How to pass a TimeSpan object to a WCF method using JSON

别说谁变了你拦得住时间么 提交于 2019-12-01 22:21:58
问题 I'm trying to find a way to call a WCF method using JSON and pass a TimeSpan as parameter but I always receive a "Bad request" response from the service. Here is a snippet code service interface: [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)] TimeSpan GetTimeSpan(TimeSpan value); Service call: String method = "GetTimeSpan"; String result = null; HttpWebRequest request = (HttpWebRequest

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

点点圈 提交于 2019-12-01 18:05:48
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 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

Why those different string formats on TimeSpan on XAML?

一笑奈何 提交于 2019-12-01 16:47:18
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 the other. EDIT: The more I work with WPF the more I feel it's not a mature enought product. I'm no