当前位置: 首页>>代码示例>>C#>>正文


C# DateTimeFormatInfo类代码示例

本文整理汇总了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);
        }
开发者ID:chcosta,项目名称:corefx,代码行数:31,代码来源:DateTimeFormatInfoGetInstance.cs

示例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);
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:7,代码来源:DateTimeFormatInfoAbbreviatedMonthGenitiveNames.cs

示例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;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:33,代码来源:datetimeformatinfogetformat.cs

示例4: GetMonthName

 public void GetMonthName(DateTimeFormatInfo format, string[] expected)
 {
     for (int i = MinMonth; i <= MaxMonth; ++i)
     {
         Assert.Equal(expected[i], format.GetMonthName(i));
     }
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:7,代码来源:DateTimeFormatInfoGetMonthName.cs

示例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);
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:7,代码来源:DateTimeFormatInfoDayNames.cs

示例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;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:26,代码来源:datetimeformatinforeadonly.cs

示例7: AMDesignator_Set

 public void AMDesignator_Set()
 {
     string newAMDesignator = "AA";
     var format = new DateTimeFormatInfo();
     format.AMDesignator = newAMDesignator;
     Assert.Equal(newAMDesignator, format.AMDesignator);
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:7,代码来源:DateTimeFormatInfoAMDesignator.cs

示例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);
        }
开发者ID:ESgarbi,项目名称:corefx,代码行数:29,代码来源:DateTimeFormatInfoClone.cs

示例9: GetAbbreviatedMonthName

 public void GetAbbreviatedMonthName(DateTimeFormatInfo info, string[] expected)
 {
     for (int i = MinMonth; i <= MaxMonth; ++i)
     {
         Assert.Equal(expected[i], info.GetAbbreviatedMonthName(i));
     }
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:7,代码来源:DateTimeFormatInfoGetAbbreviatedMonthName.cs

示例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);
    }
开发者ID:Siddhartha261,项目名称:IGRSS,代码行数:59,代码来源:Global.asax.cs

示例11: NegTest1

 public void NegTest1()
 {
     DateTimeFormatInfo info = new DateTimeFormatInfo();
     Assert.Throws<ArgumentOutOfRangeException>(() =>
     {
         info.GetAbbreviatedDayName((DayOfWeek)(-1));
     });
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:8,代码来源:DateTimeFormatInfoGetDayName.cs

示例12: GetMonthName

    public static string GetMonthName(DateTime dateValue)
    {
        DateTimeFormatInfo info = new DateTimeFormatInfo();
        string[] names;

        names = info.MonthNames;

        return names[dateValue.Month - 1];
    }
开发者ID:poweranand,项目名称:viskan,代码行数:9,代码来源:index.aspx.cs

示例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();
 }
开发者ID:hexadron,项目名称:lp3,代码行数:9,代码来源:Tshirts.cs

示例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);
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:10,代码来源:DateTimeFormatInfoCalendar.cs

示例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 };
        }
开发者ID:eerhardt,项目名称:corefx,代码行数:12,代码来源:CultureInfoDateTimeFormat.cs


注:本文中的DateTimeFormatInfo类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。