How can I convert an int 90, for example, to DateTime 1:30 in C# 3.0?
Thanks!!
Extract time only from datetime with formula 1. Select a blank cell, and type this formula =TIME(HOUR(A1),MINUTE(A1), SECOND(A1)) (A1 is the first cell of the list you want to extract time from), press Enter button and drag the fill handle to fill range.
If you subtract one DateTime from another, you'll get a TimeSpan result automatically. It has members that can give you total minutes or seconds or hours, etc., or the individual parts.
Use pandas. to_datetime() to Convert Integer to Date & Time Format. Let's suppose that your integers contain both the date and time. In that case, the format should be specify is '%Y%m%d%H%M%S' .
You shouldn't use a DateTime to represent a span of time - use TimeSpan for that. And in such a case, you'd use this:
TimeSpan ts = TimeSpan.FromMinutes(90);
If you insist that you need a DateTime, you could do the following:
DateTime dt = DateTime.Now.Date; // To get Midnight Today
dt = dt.AddMinutes(90); // to get 90-minutes past midnight Today.
The reason you probably don't want to use DateTime, though, is that it (aptly named) combines the concept of Date with the concept of Time. Your question suggests that you're planning to ignore the date component, so in the interests of using the right tool for the job, I suggest TimeSpan.
If you use C# 4 (VS 2010) you need this snippet:
TimeSpan ts = TimeSpan.FromSeconds(90);
txtDate = string.Format("Full time: {0}", new DateTime(ts.Ticks).ToString("HH:mm:ss"));
it output
Full time: 00:01:30
Or if you're trying to add time to a DateTime with just a date:
DateTime dt = dateTime.AddMinutes(90);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With