0
A
回答
0
您应该为current thread设置适当的文化。 DateTime.Parse从当前线程(顺便说一句,I love you, Reflector!)的培养使用日期设置:
public static DateTime Parse(string s)
{
return DateTimeParse.Parse(s, DateTimeFormatInfo.CurrentInfo, DateTimeStyles.None);
}
其中 “DateTimeFormatInfo.CurrentInfo” 是:
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));
}
}
有很多如何对全球化,只是尝试搜索它们(example of such how-to :))
0
如果它是一个日期对象,那么你只需要使用ToString方法来格式化它。
http://msdn.microsoft.com/en-us/library/system.datetime.tostring.aspx
代码示例:
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
0
你的问题是,你分配在aspx文件的日期和期望的格式是MM/DD/YYYY时,它可能是DD/MM/yyyy所以它吹了。您是否正在部署到使用不同日期格式的系统?
如果是这样,也许手动通过代码添加范围,并使用期望日期对象的预期格式分配它们。
例如,
YourDateValidator.MaximumValue = YourMaxDateTimeObject;
YourDateValidator.MinimumValue = YourMinDateTimeObject;
+0
@Jack如果这个答案或另一个帮助你,你应该设置一个被接受的答案,以便其他人阅读这个问题可以找到帮助你的解决方案。 – Kelsey 2010-08-18 16:03:39
相关问题
- 1. 无法将类型'[String:Any Object]'转换为预期类型'String'
- 2. 无法转换日期datetime64
- 3. 无法将Db日期转换为DateTime
- 4. SQL:无法转换为日期
- 5. 无法将System.String转换为类类型
- 6. 无法从BSON类型的字符串转换成日期
- 7. 无法过滤视图(日期类型转换错误)
- 8. 将英文日期转换为“日期”类型的值?
- 9. 将日期范围转换为R中的日期类型
- 10. T-SQL:将varchar日期列转换为日期类型
- 11. 从字符串转换为类型'日期'是无效的
- 12. 将varchar值“ - ”转换为日期类型时转换失败INT
- 13. 如何将系统日期转换为日期格式转换为日期数据类型
- 14. 无法将类型`UnityEngine.GameObject'转换为`UnityEngine.Rigidbody'
- 15. 无法转换为尺寸:类型= 0x12
- 16. TypeLoadExceptionHolder无法转换为类型
- 17. 无法转换为指针类型
- 18. 无法从BSON类型字符串转换为聚合管道上的日期
- 19. 无法转换int类型的值与预期参数类型“...”
- 20. 无法转换类型'UInt32!'的值预期参数类型“UIFontDescriptorSymbolicTraits”
- 21. 无法转换类型'nsindexpath?'的值预期参数类型“[nsindexpath]”
- 22. 无法转换类型
- 23. 无法将...转换为期望的参数类型'PFIdResultBlock?'
- 24. 无法将值类型“”转换为预期参数“UInt64'
- 25. 类型为“xxx”的对象无法转换为“yyy”类型
- 26. 无法将类型为'System.Int32'的对象转换为类型'System.Web.Security.Cryptography.Purpose'
- 27. 无法将'UIImage'类型的值转换为期望的参数类型'String'
- 28. 无法将'NSArray'类型的值转换为期望的参数类型'[Any]!'
- 29. 无法将类型'String'的值转换为期望的参数类型'NSManagedObject'Swift
- 30. 无法将'UIAlertAction'类型的值转换为期望的参数类型'UIViewController'?
你真的应该包括在这个网站上的问题的文本,因为你的链接的线程可能会消失,然后这个线程将是无用的,因为在将来如果有人读它,他们会不知道你在说什么指的是。 – Kelsey 2009-06-01 21:48:39