C# DateTime.Today (Current Day With Zero Time) - Dot Net ...

文章推薦指數: 80 %
投票人數:10人

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.



請為這篇文章評分?