可能重复:
获取系统日期和拆分日、月和年
获取 MM/dd/yyyy 的 CultureInfo.InvariantCulture 格式。但我想获得 dd/MM/yyyy 格式,我想分割日月年。
这是我的代码:
string sDate = string.Empty;
DateTime _date = DateTime.Now;
DateTime dateFormat = Convert.ToDateTime(_date.ToString(CultureInfo.InvariantCulture));
int count = 0;
string format = "dd/MM/yyyy";
sDate = dateFormat.ToString(format);
string[] Words = sDate.Split(new char[] { '/' });
foreach (string Word in Words)
{
count += 1;
if (count == 1) { Day = Word; }
if (count == 2) { Month = Word; }
if (count == 3) { Year = Word; }
}