C# DateTime.Today (Current Day With Zero Time) - Dot Net ...
文章推薦指數: 80 %
DateTime.Today returns just the day—without the time. This is different from DateTime.Now, which returns as much information as it can. HomeSearchC#DateTime.Today(CurrentDayWithZeroTime)UsetheDateTime.Todaypropertytogetthecurrentday.Todayhasnotimepart.DateTime.Todayreturnsjusttheday—withoutthetime.ThisisdifferentfromDateTime.Now,whichreturnsasmuchinformationasitcan.TheTodaypropertyreturnsaDateTimestructwiththehour,minutesandsecondssettozero.DateTime.NowExample.Thisprogramgetsthecurrentday(withToday)andthecurrenttime(withNow).Theprogramwasexecutedintheearlyafternoon,butTodayisstillsettomidnight.TodayisthesameastheNowproperty.Butithasnotimepart.TipThisprogramwasrunonaspecificdate.Whenyourunitonyourcomputer,thetimewilldiffer.Usage.TodayisusefulifyouneedtousearangeofDateTimesstartingonthecurrentday.YoucoulddeterminewhetherapieceofdatawasupdatedtodayornotbytestingitagainstDateTime.Today.DateTimeC#programthatusesDateTime.TodayusingSystem; classProgram { staticvoidMain() { DateTimetoday=DateTime.Today; DateTimenow=DateTime.Now; Console.WriteLine(today); Console.WriteLine(now); } }2/25/201112:00:00AM 2/25/20111:29:21PMSummary.WeusedtheDateTime.Todayproperty,whichhasanimportantdifferencefromDateTime.Now.Itcontainsnovaluesotherthanthecurrentday.Thismakesitusefulforsortingandfilteringtasks,orwhenyousimplydon'tneedthetime.NoteYoucangetDateTime.TodayfromDateTime.Nowonyourownaswell.Simplyremovethehours,minutesandseconds.Home©2007-2022samallen.seesiteinfoonthechangelog.
延伸文章資訊
- 1C# DateTime Format:Working with Date &Time format in C#|
This blog describes how to format DateTime in C# with a code sample. ... We can easily convert it...
- 2【C#】《DateTime》獲取時間到毫秒的方式(今天、昨天、明天
說明: 來看看C#獲取時間到毫秒的方式(今天、昨天、明天、日期比大小) /*獲取今天日期(只有日期)*/DateTime GetNowDate = DateTime.Today; Outp.
- 3Working with Date and Time in C# - TutorialsTeacher
C# includes DateTime struct to work with dates and times. To work with date and ... Today; // ret...
- 4Date and time in C# - working with date and time in CSharp
In our first example, we get today's date. Program.cs. DateTime now = DateTime.Now; Console.Write...
- 5C# DateTime.Today (Current Day With Zero Time) - Dot Net ...
DateTime.Today returns just the day—without the time. This is different from DateTime.Now, which ...