1.修改系统时间格式,可以点击系统右下角日期设置时间和日期再更改日历设置.
2.代码方式,string date = string.Format("{0:yyyy-MM-dd}",DateTime.Now.Date);
这个与操作系统有关,就是culture有关。你可以参考一这个代码:
using System;
using System.Globalization;
public class ParseDate
{
public static void Main()
{
// Define cultures to be used to parse dates.
CultureInfo[] cultures = {CultureInfo.CreateSpecificCulture("en-US"),
CultureInfo.CreateSpecificCulture("fr-FR"),
CultureInfo.CreateSpecificCulture("de-DE")};
// Define string representations of a date to be parsed.
string[] dateStrings = {"01/10/2009 7:34 PM",
"10.01.2009 19:34",
"10-1-2009 19:34" };
// Parse dates using each culture.
foreach (CultureInfo culture in cultures)
{
DateTime dateValue;
Console.WriteLine("Attempted conversions using {0} culture.",
culture.Name);
foreach (string dateString in dateStrings)
{
try {
dateValue = DateTime.Parse(dateString, culture);
Console.WriteLine(" Converted '{0}' to {1}.",
dateString, dateValue.ToString("f", culture));
}
catch (FormatException) {
Console.WriteLine(" Unable to convert '{0}' for culture {1}.",
dateString, culture.Name);
}
}
Console.WriteLine();
}
}
}
yyyy-MM-dd HH:mm:ss 将日期转换成24小时制表示
yyyy-MM-dd hh:mm:ss 将日期转换成12小时制表示
关键在小时的表示上,hh/HH
yyyy-MM-dd HH:mm:ss 将日期转换成24小时制表示
DateTime.Now.Date.ToString("yyyy-MM-dd hh:mm:ss.fff")