.Net:无法将DateRange转换为类型';日期
.Net:无法将DateRange转换为类型';日期,.net,.net,我也有同样的问题。我的日期格式是MM/dd/yyyy。如何在系统中找到日期格式并用代码更改它。如果是日期对象,则只需使用ToString方法对其进行格式化 代码示例: using System; public class DateToStringExample { public static void Main() { DateTime dateValue = new DateTime(2008, 6, 15, 21, 15, 07); // Create
我也有同样的问题。我的日期格式是MM/dd/yyyy。如何在系统中找到日期格式并用代码更改它。如果是日期对象,则只需使用ToString方法对其进行格式化 代码示例:
using System;
public class DateToStringExample
{
public static void Main()
{
DateTime dateValue = new DateTime(2008, 6, 15, 21, 15, 07);
// Create an array of standard format strings.
string[] standardFmts = {"d", "D", "f", "F", "g", "G", "m", "o",
"R", "s", "t", "T", "u", "U", "y"};
// Output date and time using each standard format string.
foreach (string standardFmt in standardFmts)
Console.WriteLine("{0}: {1}", standardFmt,
dateValue.ToString(standardFmt));
Console.WriteLine();
// Create an array of some custom format strings.
string[] customFmts = {"h:mm:ss.ff t", "d MMM yyyy", "HH:mm:ss.f",
"dd MMM HH:mm:ss", @"\Mon\t\h\: M", "HH:mm:ss.ffffzzz" };
// Output date and time using each custom format string.
foreach (string customFmt in customFmts)
Console.WriteLine("'{0}': {1}", customFmt,
dateValue.ToString(customFmt));
}
}
// This example displays the following output to the console:
// d: 6/15/2008
// D: Sunday, June 15, 2008
// f: Sunday, June 15, 2008 9:15 PM
// F: Sunday, June 15, 2008 9:15:07 PM
// g: 6/15/2008 9:15 PM
// G: 6/15/2008 9:15:07 PM
// m: June 15
// o: 2008-06-15T21:15:07.0000000
// R: Sun, 15 Jun 2008 21:15:07 GMT
// s: 2008-06-15T21:15:07
// t: 9:15 PM
// T: 9:15:07 PM
// u: 2008-06-15 21:15:07Z
// U: Monday, June 16, 2008 4:15:07 AM
// y: June, 2008
//
// 'h:mm:ss.ff t': 9:15:07.00 P
// 'd MMM yyyy': 15 Jun 2008
// 'HH:mm:ss.f': 21:15:07.0
// 'dd MMM HH:mm:ss': 15 Jun 21:15:07
// '\Mon\t\h\: M': Month: 6
// 'HH:mm:ss.ffffzzz': 21:15:07.0000-07:00
您的问题是,您在aspx文件中分配了日期,并希望格式为mm/dd/yyyy,而它可能是dd/mm/yyyy,因此它被放大了。您是否部署到使用不同日期格式的系统 如果是这样,可以通过代码手动添加范围,并使用预期的格式(即预期的日期对象)分配它们 例如
你应该为一个家庭建立适当的文化。Parse使用当前线程的区域性中的日期设置(顺便说一句,): 其中“DateTimeFormatInfo.CurrentInfo”是:
关于全球化有很多方法,只要试着搜索它们(:))你真的应该把问题的文本也包括在这个网站上,因为你的链接线程可能会消失,然后这个线程就没用了,因为将来如果有人阅读它,他们就不知道你指的是什么。@Jack如果这个答案或其他答案对你有帮助,您应该设置一个可接受的答案,以便阅读此问题的其他人能够找到帮助您的解决方案。
YourDateValidator.MaximumValue = YourMaxDateTimeObject;
YourDateValidator.MinimumValue = YourMinDateTimeObject;
public static DateTime Parse(string s)
{
return DateTimeParse.Parse(s, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None);
}
public static DateTimeFormatInfo CurrentInfo
{
get
{
CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
if (!currentCulture.m_isInherited)
{
DateTimeFormatInfo dateTimeInfo = currentCulture.dateTimeInfo;
if (dateTimeInfo != null)
{
return dateTimeInfo;
}
}
return (DateTimeFormatInfo) currentCulture.GetFormat(typeof(DateTimeFormatInfo));
}
}