c#获取当前系统时间,并提取按格式提取年月日为字符串
2021-04-01 02:24
标签:parse ring add 时间 code rgs tostring main style c#获取当前系统时间,并提取按格式提取年月日为字符串 标签:parse ring add 时间 code rgs tostring main style 原文地址:https://www.cnblogs.com/PanDaSong/p/9246373.htmlclass Program
{
static void Main(String[] args)
{
DateTime currentTime = System.DateTime.Now;
string defaultYear = currentTime.Year.ToString("d4");
string defaultMonth = currentTime.Month.ToString("d2");//例:“06”
//string defaultDay = currentTime.Day.ToString("d2");
//string defaultHour = currentTime.Hour.ToString("d2");
string defaultDay = currentTime.AddHours(-24).Day.ToString("d2");
string dateString1 = defaultYear + defaultMonth + defaultDay + "08";
DateTime dt1 = DateTime.ParseExact(dateString1,"yyyyMMddHH",System.Globalization.CultureInfo.CurrentCulture);
dateTimePicker1.Value = dt1;
}
}