How can I “trim” a property value DateTimein C #?
DateTime
For example, when I get a date, it has the format "10/1/2010 00:00:00".
How can I “crop” the “Time” 00:00:00 without converting it to a string?
Since I use a type property DateTimeto control this, I do not need to convert to String.
Any help is appreciated.
var dt = DateTime.Now; // 10/1/2010 10:44:24 AM var dateOnly = dt.Date; // 10/1/2010 12:00:00 AM
, DateTime , - . , Date, Date DateTime. , . .
DateTime now = DateTime.Now; DateTime today = now.Date;
DateTime now = DateTime.Now; DateTime today = new DateTime(now.Year, now.Month, now.Day);
, .
DateTime t = DateTime.Now; DateTime t2 = t - new TimeSpan(t.Ticks % TimeSpan.TicksPerDay);
TicksPerHour, TicksPerMinute TicksPerSecond.
DateTime, .ToString() it?
DateTime current = DateTime.Now; string myTime = current.TimeOfDay.Tostring()
...
. DateTime , 00:00:00
.
var now = DateTime.Now; var today = now.Date;
. , timtowtdi phili:
timtowtdi
var now = DateTime.Now; var today = now.Add(-now.TimeOfDay);
Source: https://habr.com/ru/post/1767580/More articles:WITH#. Determine at run time if the property is an instance of a type or object? - reflectionWhy do file formats have magic numbers? - file-formatWhy doesn't the compiler warn about definitions without names? - c ++How to determine if browser window is activated - javascriptCreating an administration area for managing a dynamic website - c #Conditionally returning objects in Java (without iterators) - javaVideoView and step-by-step playback (frame by frame) - androidStructural Question Typedef - cObjective-c расширения класса неэффекты в статической библиотеке - objective-cThe fastest way to draw a series of bitmaps using C # - c #All Articles