本文整理汇总了C#中DateTimeFormatInfo类的典型用法代码示例。如果您正苦于以下问题:C# DateTimeFormatInfo类的具体用法?C# DateTimeFormatInfo怎么用?C# DateTimeFormatInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DateTimeFormatInfo类属于命名空间,在下文中一共展示了DateTimeFormatInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssertSameValues
private void AssertSameValues(DateTimeFormatInfo expected, DateTimeFormatInfo value)
{
if (value.Equals(expected))
{
// same instance, we don't have to test the values
return;
}
Assert.Equal(expected.AbbreviatedDayNames, value.AbbreviatedDayNames);
Assert.Equal(expected.AbbreviatedMonthGenitiveNames, value.AbbreviatedMonthGenitiveNames);
Assert.Equal(expected.AbbreviatedMonthNames, value.AbbreviatedMonthNames);
Assert.Equal(expected.DayNames, value.DayNames);
Assert.Equal(expected.MonthGenitiveNames, value.MonthGenitiveNames);
Assert.Equal(expected.MonthNames, value.MonthNames);
Assert.Equal(expected.ShortestDayNames, value.ShortestDayNames);
Assert.Equal(expected.AMDesignator, value.AMDesignator);
Assert.Equal(expected.FullDateTimePattern, value.FullDateTimePattern);
Assert.Equal(expected.LongDatePattern, value.LongDatePattern);
Assert.Equal(expected.LongTimePattern, value.LongTimePattern);
Assert.Equal(expected.MonthDayPattern, value.MonthDayPattern);
Assert.Equal(expected.PMDesignator, value.PMDesignator);
Assert.Equal(expected.RFC1123Pattern, value.RFC1123Pattern);
Assert.Equal(expected.ShortDatePattern, value.ShortDatePattern);
Assert.Equal(expected.ShortTimePattern, value.ShortTimePattern);
Assert.Equal(expected.SortableDateTimePattern, value.SortableDateTimePattern);
Assert.Equal(expected.UniversalSortableDateTimePattern, value.UniversalSortableDateTimePattern);
Assert.Equal(expected.YearMonthPattern, value.YearMonthPattern);
Assert.Equal(expected.CalendarWeekRule, value.CalendarWeekRule);
Assert.Equal(expected.FirstDayOfWeek, value.FirstDayOfWeek);
}
示例2: AbbreviatedMonthNames_Set
public void AbbreviatedMonthNames_Set()
{
string[] newAbbreviatedMonthGenitiveNames = new string[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "" };
var format = new DateTimeFormatInfo();
format.AbbreviatedMonthGenitiveNames = newAbbreviatedMonthGenitiveNames;
Assert.Equal(newAbbreviatedMonthGenitiveNames, format.AbbreviatedMonthGenitiveNames);
}
示例3: PosTest1
public bool PosTest1()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest1: Call GetFormat to to get an valid DateTimeFormatInfo instance");
try
{
DateTimeFormatInfo expected = new DateTimeFormatInfo();
object obj = expected.GetFormat(typeof(DateTimeFormatInfo));
if (!(obj is DateTimeFormatInfo))
{
TestLibrary.TestFramework.LogError("001.1", "Calling GetFormat returns a non DateTimeFormatInfo instance");
retVal = false;
}
DateTimeFormatInfo actual = obj as DateTimeFormatInfo;
if (actual != expected)
{
TestLibrary.TestFramework.LogError("001.2", "Calling GetFormat returns wrong instance");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}
示例4: GetMonthName
public void GetMonthName(DateTimeFormatInfo format, string[] expected)
{
for (int i = MinMonth; i <= MaxMonth; ++i)
{
Assert.Equal(expected[i], format.GetMonthName(i));
}
}
示例5: DayNames_Set
public void DayNames_Set()
{
string[] newDayNames = new string[] { "1", "2", "3", "4", "5", "6", "7" };
var format = new DateTimeFormatInfo();
format.DayNames = newDayNames;
Assert.Equal(newDayNames, format.DayNames);
}
示例6: PosTest1
public bool PosTest1()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest1: Call ReadOnly on a writable DateTimeFormatInfo instance");
try
{
DateTimeFormatInfo info = new DateTimeFormatInfo();
DateTimeFormatInfo actual = DateTimeFormatInfo.ReadOnly(info);
if (!actual.IsReadOnly)
{
TestLibrary.TestFramework.LogError("001.1", "Calling ReadOnly on a writable DateTimeFormatInfo instance does not make the instance read only");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("001.0", "Unexpected exception: " + e);
TestLibrary.TestFramework.LogInformation(e.StackTrace);
retVal = false;
}
return retVal;
}
示例7: AMDesignator_Set
public void AMDesignator_Set()
{
string newAMDesignator = "AA";
var format = new DateTimeFormatInfo();
format.AMDesignator = newAMDesignator;
Assert.Equal(newAMDesignator, format.AMDesignator);
}
示例8: Clone
public void Clone(DateTimeFormatInfo format)
{
DateTimeFormatInfo clone = (DateTimeFormatInfo)format.Clone();
Assert.NotSame(format, clone);
Assert.False(clone.IsReadOnly);
Assert.Equal(format.AbbreviatedDayNames, clone.AbbreviatedDayNames);
Assert.Equal(format.AbbreviatedMonthGenitiveNames, clone.AbbreviatedMonthGenitiveNames);
Assert.Equal(format.AbbreviatedMonthNames, clone.AbbreviatedMonthNames);
Assert.Equal(format.DayNames, clone.DayNames);
Assert.Equal(format.MonthGenitiveNames, clone.MonthGenitiveNames);
Assert.Equal(format.MonthNames, clone.MonthNames);
Assert.Equal(format.ShortestDayNames, clone.ShortestDayNames);
Assert.Equal(format.AMDesignator, clone.AMDesignator);
Assert.Equal(format.FullDateTimePattern, clone.FullDateTimePattern);
Assert.Equal(format.LongDatePattern, clone.LongDatePattern);
Assert.Equal(format.LongTimePattern, clone.LongTimePattern);
Assert.Equal(format.MonthDayPattern, clone.MonthDayPattern);
Assert.Equal(format.PMDesignator, clone.PMDesignator);
Assert.Equal(format.RFC1123Pattern, clone.RFC1123Pattern);
Assert.Equal(format.ShortDatePattern, clone.ShortDatePattern);
Assert.Equal(format.ShortTimePattern, clone.ShortTimePattern);
Assert.Equal(format.SortableDateTimePattern, clone.SortableDateTimePattern);
Assert.Equal(format.UniversalSortableDateTimePattern, clone.UniversalSortableDateTimePattern);
Assert.Equal(format.YearMonthPattern, clone.YearMonthPattern);
Assert.Equal(format.CalendarWeekRule, clone.CalendarWeekRule);
Assert.Equal(format.FirstDayOfWeek, clone.FirstDayOfWeek);
}
示例9: GetAbbreviatedMonthName
public void GetAbbreviatedMonthName(DateTimeFormatInfo info, string[] expected)
{
for (int i = MinMonth; i <= MaxMonth; ++i)
{
Assert.Equal(expected[i], info.GetAbbreviatedMonthName(i));
}
}
示例10: SetFormViewParameters
public static void SetFormViewParameters(IOrderedDictionary parameters, object instance)
{
Type ObjType = instance.GetType();
foreach (DictionaryEntry parameter in parameters)
{
PropertyInfo property = ObjType.GetProperty(parameter.Key.ToString());
if (property != null)
{
Type t = property.PropertyType;
object value = null;
switch (t.Name)
{
case "Decimal":
if (!string.IsNullOrEmpty(parameter.Value.ToString()))
value = Convert.ToDecimal(parameter.Value);
else
value = Convert.ToDecimal(0.0);
break;
case "Boolean":
value = Convert.ToBoolean(parameter.Value);
break;
case "DateTime":
String DateTimeFormat = "dd/MM/yyyy";
DateTimeFormatInfo info = new DateTimeFormatInfo();
info.ShortDatePattern = DateTimeFormat;
String date = Convert.ToString(parameter.Value);
if (!String.IsNullOrEmpty(date) || date == "null")
value = Convert.ToDateTime(date,info);
break;
case "Double":
if (!string.IsNullOrEmpty(parameter.Value.ToString()))
value = Convert.ToDouble(parameter.Value);
else
value = 0.0;
break;
case "Int32":
value = Convert.ToInt32(parameter.Value);
break;
case "Single":
value = Convert.ToSingle(parameter.Value);
break;
case "String":
value = Convert.ToString(parameter.Value);
break;
case "Guid":
if (!string.IsNullOrEmpty(parameter.Value.ToString()))
value = new Guid("11111111111111111111111111111111");
break;
default:
break;
}
property.SetValue(instance, value, null);
}
}
parameters.Clear();
parameters.Add("Values", instance);
}
示例11: NegTest1
public void NegTest1()
{
DateTimeFormatInfo info = new DateTimeFormatInfo();
Assert.Throws<ArgumentOutOfRangeException>(() =>
{
info.GetAbbreviatedDayName((DayOfWeek)(-1));
});
}
示例12: GetMonthName
public static string GetMonthName(DateTime dateValue)
{
DateTimeFormatInfo info = new DateTimeFormatInfo();
string[] names;
names = info.MonthNames;
return names[dateValue.Month - 1];
}
示例13: not_expired
public static List<tshirt> not_expired()
{
DateTimeFormatInfo format = new DateTimeFormatInfo();
format.ShortDatePattern = "MM/dd/yyyy";
DateTime now = Convert.ToDateTime(DateTime.Now.Date, format);
return (from s in db.tshirts
where s.expire_time > now
select s).ToList();
}
示例14: Calendar_Set
public void Calendar_Set()
{
Calendar newCalendar = new GregorianCalendar(GregorianCalendarTypes.Localized);
var format = new DateTimeFormatInfo();
format.Calendar = newCalendar;
Assert.Equal(newCalendar, format.Calendar);
format.Calendar = newCalendar;
Assert.Equal(newCalendar, format.Calendar);
}
示例15: DateTimeFormatInfo_Set_TestData
public static IEnumerable<object[]> DateTimeFormatInfo_Set_TestData()
{
DateTimeFormatInfo customDateTimeFormatInfo1 = new DateTimeFormatInfo();
customDateTimeFormatInfo1.AMDesignator = "a.m.";
customDateTimeFormatInfo1.MonthDayPattern = "MMMM-dd";
customDateTimeFormatInfo1.ShortTimePattern = "HH|mm";
yield return new object[] { "en-US", customDateTimeFormatInfo1 };
DateTimeFormatInfo customDateTimeFormatInfo2 = new DateTimeFormatInfo();
customDateTimeFormatInfo2.LongTimePattern = "H:mm:ss";
yield return new object[] { "fi-FI", customDateTimeFormatInfo2 };
}