Search results
17 lut 2011 · DateTime datetime = DateTime.Parse(myDateString); string timeString = datetime.ToShortTimeString(); Console.WriteLine(timeString); // 6:46 PM. You can format the parsed datetime to a string in many other ways, but the ToShortTimeString does exactly what you want. edited Feb 4, 2013 at 4:13.
22 cze 2009 · There is only DateTime type in C# and it consist of both the date and time portion. If you don't care about the Date portion of DateTime, set it to default value like this: DateTime myTime = default(DateTime).Add(myDateTime.TimeOfDay)
2 maj 2023 · Using DateTime for a time of day requires that an arbitrary date be associated with the time, and then later disregarded. It's common practice to choose DateTime.MinValue (0001-01-01) as the date, however, if hours are subtracted from the DateTime value, an OutOfRange exception might occur.
19 cze 2022 · The best way to get time from DateTime in C# is to: Access the TimeOfDay property of DateTime to get TimeSpan value for your DateTime . Access the Hours property of TimeSpan to get the hour of the DateTime .
10 lis 2023 · We can add values to a DateTime with methods like AddDays, AddMonths and Add() which receives a TimeSpan. The most versatile method is Add(), and we can add any TimesSpan.
8 lip 2023 · C# DateTime. The DateTime value type represents dates and times with values ranging from 00:00:00 (midnight), January 1, 0001 Anno Domini (Common Era) through 11:59:59 P.M., December 31, 9999 A.D. (C.E.) in the Gregorian calendar. C# TimeSpan.
Convert String to DateTime. A valid date and time string can be converted to a DateTime object using Parse(), ParseExact(), TryParse() and TryParseExact() methods. The Parse() and ParseExact() methods will throw an exception if the specified string is not a valid representation of a date and time.