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.
延伸文章資訊
- 1How do I get today's date in C# in mm/dd/yyyy format? - Stack ...
string today = DateTime.Today.ToString("M/d");.
- 2【C#】《DateTime》獲取時間到毫秒的方式(今天、昨天、明天
說明: 來看看C#獲取時間到毫秒的方式(今天、昨天、明天、日期比大小) /*獲取今天日期(只有日期)*/DateTime GetNowDate = DateTime.Today; Outp.
- 3C# DateTime.Today屬性代碼示例- 純淨天空
C# DateTime.Today屬性代碼示例,System.DateTime.Today用法.
- 4DateTime.Today 屬性(System) | Microsoft Docs
DateTime thisDay = DateTime.Today; // Display the date in the default (general) format. Console.W...
- 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 ...