timespan

TimeSpan Conversion

冷暖自知 提交于 2020-02-24 17:57:25
问题 I want to convert minutes to seconds and at the moment I have a problem because in the minute textbox when I type 1.50 the outcome is 90 seconds which is wrong because 1.30 = 90 seconds private void MtoCbutton_Click(object sender, EventArgs e) { if (minTosecTextBox.Text != "Minutes") { minutes = Convert.ToDouble(minTosecTextBox.Text); TimeSpan span = TimeSpan.FromMinutes(minutes); resultSectextBoxtextBox.Text = span.TotalSeconds.ToString(); } else { MessageBox.Show("Please enter Minutes"); }

codeigniter timespan function

被刻印的时光 ゝ 提交于 2020-01-25 02:54:27
问题 Hello i have now search the hole web and found a lot but i just dont know how to make it to work so now im asking here for help i want to do so then a person create a comment it should said "created 1 sec. ago" and then 1 min and 1 hour and like that :) can some one help me with that ? thanks 回答1: This is basically human readable format, and can be completed by mathematical checks to check the distance of times, working snippet below: function RelativeTime($timestamp) { $difference = time() -

What is a good format for Duration in JSON?

情到浓时终转凉″ 提交于 2020-01-24 10:52:18
问题 I realise that JSON has no real date format and that using ISO 8601 is a good bet given that's what JavaScript uses. What about a duration? JavaScript has no built in format. I came across ISO 8601 Durations e.g. P3Y6M4DT12H30M5S which I haven't seen used much in the wild. It also looks very verbose and difficult to read. As far as I can see it also does not support milliseconds if you needed that. I'm using C# whose TimeSpan type outputs 1.02:03:04.0050000 for 1 day, 2 hours, 3 minutes, 4

How to produce “human readable” strings to represent a TimeSpan

无人久伴 提交于 2020-01-20 02:34:05
问题 I have a TimeSpan representing the amount of time a client has been connected to my server. I want to display that TimeSpan to the user. But I don't want to be overly verbose to displaying that information (ex: 2hr 3min 32.2345sec = too detailed!) For example: If the connection time is... > 0 seconds and < 1 minute -----> 0 Seconds > 1 minute and < 1 hour -----> 0 Minutes, 0 Seconds > 1 hour and < 1 day -----> 0 Hours, 0 Minutes > 1 day -----> 0 Days, 0 Hours And of course, in cases where the

System.FormatException on TimeSpan.ToString()

三世轮回 提交于 2020-01-15 10:39:13
问题 I have a float that represent a quantity of seconds and I need to format it to match this: I need to format an elapsed time (in seconds) like this: HH:mm:ss.fff // Like 01:15:22.150 Here is my code: TimeSpan timeSpan = new TimeSpan(0, h, m, s, ms); string time = timeSpan.ToString(@"HH\:mm\:ss.fff"); // Throw a System.FormatException It don't throw exception if I use ´@"hh:mm:ss"´ but I need the milliseconds... What is the right string format? I use this TimeSpan constructor. 回答1: There's 2

Best way to work with timespans?

天大地大妈咪最大 提交于 2020-01-14 14:00:09
问题 Is there a preferred class or method for working with timespans in PHP? The primary functionality I am interested in is checking if a date is within the timespan, or generating timestamps for the lower and upper limits. 回答1: use the unix timestamp. If it's mysql data, then you can store timestamps like this, if not then you can also convert mysql datetimes to unix timestamps. There is a bunch of documentation on the functionality pertaining to this at the php.net site, but it's all relatively

.Net Core 3.0 TimeSpan deserialization error

孤人 提交于 2020-01-13 19:43:33
问题 I am using .Net Core 3.0 and have the following string which I need to deserialize with Newtonsoft.Json: { "userId": null, "accessToken": null, "refreshToken": null, "sessionId": null, "cookieExpireTimeSpan": { "ticks": 0, "days": 0, "hours": 0, "milliseconds": 0, "minutes": 0, "seconds": 0, "totalDays": 0, "totalHours": 0, "totalMilliseconds": 0, "totalMinutes": 0, "totalSeconds": 0 }, "claims": null, "success": false, "errors": [ { "code": "Forbidden", "description": "Invalid username

Fastest way to calculate time differences in C#?

谁说我不能喝 提交于 2020-01-06 19:42:29
问题 It seems like there are a lot of ways to calculate time spans in c#. I am wondering which one is fastest and by that I simply means requires the least amount of processing. Let me throw out an example to illustrate exactly what I am trying to do. private const int timeBetweenEvents = 250; //delay ms DateTime nextUpdate = DateTime.Now.Add(new TimeSpan(0, 0, 0, timeBetweenEvents)); ... while(true) { if (DateTime.Now > nextUpdate) { // do something nextUpdate = DateTime.Now.Add(new TimeSpan(0, 0

Need only HH:MM:SS in time span string

*爱你&永不变心* 提交于 2020-01-06 06:45:14
问题 I have a time span string as 1.21:00:00 it means 45 hours and i need it as 45:00:00 is it possible to do that in c#? 回答1: Just adding my answer because the string formatting can be done easier than current suggestions. var ts = TimeSpan.Parse("1.21:00:00"); string.Format("{0}:{1:mm}:{1:ss}", ts.TotalHours, ts); // 45:00:00 Unlike Jon's answer it doesn't require escaping. And unlike Soner's answer, it doesn't require passing the parameter twice. Edit For fractional TotalHours you probably want