timespan

Parsing TimeSpan from string including format

五迷三道 提交于 2021-02-20 15:01:47
问题 I'm sure this must be simple, but I can't figure out how to word it correctly in Google... I have a config which has a field: TimeToPoll="1d" Now I want to do something like : TimeSpan.Parse(TimeToPoll); Returning a timespan of one day. In C# EDIT: I'm looking for a method which allows parse of "1d" as well as "1s" or "1y" etc. Is this possible? Meaning: "1d" parses to {1.00:00:00} "1h" parses to {0.01:00:00} "1m" parses to {0.00:01:00} "1s" parses to {0.00:00:01} 回答1: The d is not needed and

Parsing TimeSpan from string including format

℡╲_俬逩灬. 提交于 2021-02-20 14:56:03
问题 I'm sure this must be simple, but I can't figure out how to word it correctly in Google... I have a config which has a field: TimeToPoll="1d" Now I want to do something like : TimeSpan.Parse(TimeToPoll); Returning a timespan of one day. In C# EDIT: I'm looking for a method which allows parse of "1d" as well as "1s" or "1y" etc. Is this possible? Meaning: "1d" parses to {1.00:00:00} "1h" parses to {0.01:00:00} "1m" parses to {0.00:01:00} "1s" parses to {0.00:00:01} 回答1: The d is not needed and

Timespan formatting in Excel

邮差的信 提交于 2021-02-20 02:34:08
问题 I'm currently using the custom format, m:ss.00 , and it works perfectly for any times that exceed one minute, e.g. 1:02.47 . However, if I enter a time less than a minute, e.g. 57.66 , it gets transformed into 50:24.00 . I can get around this by entering 0:57.66 , but I'd rather not have to always type the leading 0: and I don't want the leading 0: displayed anyway. I'd like for it to understand that if I skip the number followed by a colon part, to interpret this as no minutes and simply

Serializing Timespan in Dictionary<string, object> with Json.NET

主宰稳场 提交于 2021-02-16 14:21:46
问题 I have a property that is actually a Dictionary. And I keep many types in this dictionary like TimeSpans, DateTimes, etc. But serializing and deserializing TimeSpans are wrong and it deserializes as string. var dict = new Dictionary<string, object>(); dict.Add("int", 15); dict.Add("string", "foo"); dict.Add("timeSpan", new TimeSpan(1,1,1)); dict.Add("dateTime", DateTime.Now); var settings = new JsonSerializerSettings{ TypeNameHandling = TypeNameHandling.All, TypeNameAssemblyFormat =

Finding the difference between two DateTimes (hours and minutes)

落花浮王杯 提交于 2021-01-29 03:22:13
问题 I'm trying to create a simple program that reads in user input for the time they went to sleep and the time they woke up, and output the total time they slept. The output shows up incorrect and I'm unsure what the problem is. I've tried two different codes but they both seem to be having the same problem. The first code was this: Console.WriteLine("Please input time you slept"); string sleepTime = Console.ReadLine(); Console.WriteLine("Please input the time you woke up"); string wakeTime =

Finding the difference between two DateTimes (hours and minutes)

泄露秘密 提交于 2021-01-29 03:17:51
问题 I'm trying to create a simple program that reads in user input for the time they went to sleep and the time they woke up, and output the total time they slept. The output shows up incorrect and I'm unsure what the problem is. I've tried two different codes but they both seem to be having the same problem. The first code was this: Console.WriteLine("Please input time you slept"); string sleepTime = Console.ReadLine(); Console.WriteLine("Please input the time you woke up"); string wakeTime =

How to determine if now(utc) is within the range of the given days of the week and times of the day in ISO 8601 format

我是研究僧i 提交于 2021-01-27 13:20:33
问题 I run into this question of how to determine if DateTime.UtcNow (e.g. 2018-01-01T20:00:00Z) falls within the given range of days and times that are in another timezone. There are no specific dates given, just the days of the week, and the time of the day. The given time is in ISO 8601 standard format. To simplify this question, it can be how to check if a UTC time is within business hours in China. For example, the given day and time range is given by someone form China in time zone +08:00,

PowerShell New-TimeSpan Displayed Friendly with Day(s) Hour(s) Minute(s) Second(s)

谁说我不能喝 提交于 2020-12-15 04:56:46
问题 I've been looking for a PowerShell script similar to examples found in .NET examples. To take a New-TimeSpan and display is at 1 day, 2 hours, 3 minutes, 4 seconds. Exclude where its zero, add plural "s" where needed. Anybody have that handy? This is as far as I got: $StartDate = (Get-Date).ToString("M/dd/yyyy h:mm:ss tt") Write-Host "Start Time: $StartDate" # Do Something $EndDate = (Get-Date).ToString("M/dd/yyyy h:mm:ss tt") Write-Host "End Time: $EndDate" -ForegroundColor Cyan $Duration =

PowerShell New-TimeSpan Displayed Friendly with Day(s) Hour(s) Minute(s) Second(s)

北城以北 提交于 2020-12-15 04:56:12
问题 I've been looking for a PowerShell script similar to examples found in .NET examples. To take a New-TimeSpan and display is at 1 day, 2 hours, 3 minutes, 4 seconds. Exclude where its zero, add plural "s" where needed. Anybody have that handy? This is as far as I got: $StartDate = (Get-Date).ToString("M/dd/yyyy h:mm:ss tt") Write-Host "Start Time: $StartDate" # Do Something $EndDate = (Get-Date).ToString("M/dd/yyyy h:mm:ss tt") Write-Host "End Time: $EndDate" -ForegroundColor Cyan $Duration =