timespan Questions

3

Solved

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, "cooki...
Claro asked 8/10, 2019 at 9:35

9

Solved

I have a collection of objects that include a TimeSpan variable: MyObject { TimeSpan TheDuration { get; set; } } I want to use LINQ to sum those times. Of course, (from r in MyCollection selec...
Cnut asked 16/1, 2011 at 0:33

3

Solved

The below code works fine : DateTime d1 = DateTime.Now; DateTime d2 = DateTime.Now.AddDays(-1); int d3 = (int)(d1 - d2).TotalDays; But what if I define DateTime as DateTime? : DateTime? d1 = Da...
Molybdic asked 23/7, 2016 at 12:28

11

Solved

In my application, a user enters two dates. A scheduled start date, and a scheduled end date. We have to take those dates, and populate 4 fields, based on the difference. So, lets say he selects 1...
Burkey asked 7/6, 2011 at 3:40

5

Solved

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.
Houchens asked 9/7, 2013 at 16:44

6

Solved

I've seen these questions but both involve methods that aren't available in the CellStyle Format value. I only want to show the hours and minutes portion (16:05); not the seconds as well (16:05:13)...
Chancroid asked 2/9, 2010 at 14:9

6

Solved

How to parse string like 30:15 to TimeSpan in C#? 30:15 means 30 hours and 15 minutes. string span = "30:15"; TimeSpan ts = TimeSpan.FromHours( Convert.ToDouble(span.Split(':')[0])). Add(TimeSpa...
Cyrus asked 28/4, 2010 at 9:45

2

Solved

I want to be able to show minutes and seconds in a textbox. The TextBox is bound towards a property, which is a TimeSpan. In the textbox, the default is : "00:00:00". This works fine, but...
Antislavery asked 12/5, 2011 at 7:33

1

I have a TimeSpan property public TimeSpan Time { get; set; } Currently using swagger to test API Trying to figure out what value value to pass here "time": {}, Tried: "time": {"01:01:01"}, ...
Soapwort asked 10/3, 2020 at 17:30

27

Solved

In C#/.NET TimeSpan has TotalDays, TotalMinutes, etc. but I can't figure out a formula for total months difference. Variable days per month and leap years keep throwing me off. How can I get TotalM...
Systole asked 6/10, 2009 at 14:36

3

Solved

The following code Console.WriteLine("{0:%h} hours {0:%m} minutes", new TimeSpan(TimeSpan.TicksPerDay)); produces this output: 0 hours 0 minutes What I would like is this output: 24 h...
Honan asked 18/4, 2011 at 14:0

10

Solved

I am trying to store a .Net TimeSpan in SQL server 2008 R2. EF Code First seems to be suggesting it should be stored as a Time(7) in SQL. However TimeSpan in .Net can handle longer periods than...
Allege asked 14/12, 2011 at 11:36

4

Solved

I have items with the properties : public int ClientId {get;set;} public DateTime StartDateTime{get;set;} public DateTime EndDateTime{get;set;} And I want to calculate the total of the differen...
Booklet asked 28/5, 2015 at 6:42

6

Solved

This is a bit wierd. Parsing a text field with a valid timespan fails if I try to be precise! const string tmp = "17:23:24"; //works var t1 = TimeSpan.Parse(tmp); //fails var t2 = TimeSpan.ParseEx...
Nadeau asked 30/7, 2012 at 9:52

7

Solved

I'm doing some math with the Timespans in .Net, and occasionally the sum results in a negative Timespan. When I display the result I am having trouble formatting it to include the negative indicato...
Impostume asked 11/7, 2010 at 17:2

5

How do I convert a TimeSpan value to a double in C#? I mean I have this -08:15:00 and I want a double -08.15.
Philanthropy asked 27/4, 2013 at 13:53

6

Solved

in c# i have time in format hhmmss like 124510 for 12:45:10 and i need to know the the TotalSeconds. i used the TimeSpan.Parse("12:45:10").ToTalSeconds but it does'nt take the format hhmmss. Any ni...
Jiva asked 2/12, 2009 at 15:56

4

Solved

How can I format a TimeSpan object to look like a time zone offset, like this: +0700 or -0600 I'm using GetUtcOffset to get an offset, and its working, but its returning a TimeSpan object.
Spikenard asked 20/1, 2013 at 0:54

1

Solved

I have a WebAPI (written in C#), a POST-method accepting a complex object with a System.TimeSpan-Property named TriggerDelay, and a React Native application from where I am passing this object in J...
Wilscam asked 25/8, 2020 at 23:18

7

Solved

Using Date.js already, but can also use another library if necessary. Not sure what is the best way to work with time deltas. Specifically, I want to display the time that has elapsed between now ...
Matrimonial asked 12/1, 2013 at 20:24

6

Solved

I have a class with 2 date properties: FirstDay and LastDay. LastDay is nullable. I would like to generate a string in the format of "x year(s) y day(s)". If the total years are less than 1, I woul...
Pubes asked 11/4, 2013 at 20:11

14

Solved

Is it ever OK to use Environment.TickCount to calculate time spans? int start = Environment.TickCount; // Do stuff int duration = Environment.TickCount - start; Console.WriteLine("That took &q...
Flaxseed asked 28/10, 2008 at 13:40

8

Solved

I want to display the elapsed time between two dates in a string. Let's say I have the following code: DateTime date1 = DateTime.Now(); System.Threading.Thread.Sleep(2500); DateTime date2 = DateT...
Ferbam asked 23/8, 2010 at 7:30

10

Solved

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 doc...
Interjection asked 16/7, 2009 at 16:19

3

Solved

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: ...
Peptidase asked 24/8, 2011 at 16:18

© 2022 - 2024 — McMap. All rights reserved.