在C#中,获取时间的方法有以下几种
在C#中,获取时间的方法有以下几种:
- 使用DateTime类的静态方法Now获取当前系统时间:
DateTimecurrentTime=DateTime.Now;
DateTimecurrentUtcTime=DateTime.UtcNow;
DateTimespecifiedTime=newDateTime(2022,12,31,23,59,59);
intyear=currentTime.Year;
intmonth=currentTime.Month;
intday=currentTime.Day;
inthour=currentTime.Hour;
intminute=currentTime.Minute;
stringformattedTime=currentTime.ToString("yyyy-MM-ddHH:mm:ss");
这些是在C#中获取时间的一些常用方法,开发中根据具体需求选择合适的方法来获取时间信息。
版权声明
本文仅代表作者观点,不代表博信信息网立场。