本文整理汇总了C#中System.Globalization.DateTimeFormatInfo.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# DateTimeFormatInfo.Clone方法的具体用法?C# DateTimeFormatInfo.Clone怎么用?C# DateTimeFormatInfo.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Globalization.DateTimeFormatInfo
的用法示例。
在下文中一共展示了DateTimeFormatInfo.Clone方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: ExpandPredefinedFormat
private static string ExpandPredefinedFormat(string format, ref DateTime dateTime, ref DateTimeFormatInfo dtfi, ref TimeSpan offset)
{
switch (format[0])
{
case 'o':
case 'O':
dtfi = DateTimeFormatInfo.InvariantInfo;
goto Label_0160;
case 'r':
case 'R':
if (offset != NullOffset)
{
dateTime -= offset;
}
else if (dateTime.Kind == DateTimeKind.Local)
{
InvalidFormatForLocal(format, dateTime);
}
dtfi = DateTimeFormatInfo.InvariantInfo;
goto Label_0160;
case 's':
dtfi = DateTimeFormatInfo.InvariantInfo;
goto Label_0160;
case 'u':
if (offset == NullOffset)
{
if (dateTime.Kind == DateTimeKind.Local)
{
InvalidFormatForLocal(format, dateTime);
}
break;
}
dateTime -= offset;
break;
case 'U':
if (offset != NullOffset)
{
throw new FormatException(Environment.GetResourceString("Format_InvalidString"));
}
dtfi = (DateTimeFormatInfo) dtfi.Clone();
if (dtfi.Calendar.GetType() != typeof(GregorianCalendar))
{
dtfi.Calendar = GregorianCalendar.GetDefaultInstance();
}
dateTime = dateTime.ToUniversalTime();
goto Label_0160;
default:
goto Label_0160;
}
dtfi = DateTimeFormatInfo.InvariantInfo;
Label_0160:
format = GetRealFormat(format, dtfi);
return format;
}
示例3: ExpandPredefinedFormat
private static string ExpandPredefinedFormat(string format, ref DateTimeFormatInfo dtfi, ref ParsingInfo parseInfo, ref DateTimeResult result)
{
char c = format[0];
if (c <= 'R')
{
if (c != 'O')
{
if (c != 'R')
{
goto IL_160;
}
goto IL_65;
}
}
else
{
if (c != 'U')
{
switch (c)
{
case 'o':
{
break;
}
case 'p':
case 'q':
case 't':
{
goto IL_160;
}
case 'r':
{
goto IL_65;
}
case 's':
{
dtfi = DateTimeFormatInfo.InvariantInfo;
parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
goto IL_160;
}
case 'u':
{
parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
dtfi = DateTimeFormatInfo.InvariantInfo;
if ((result.flags & ParseFlags.CaptureOffset) != (ParseFlags)0)
{
result.flags |= ParseFlags.UtcSortPattern;
goto IL_160;
}
goto IL_160;
}
default:
{
goto IL_160;
}
}
}
else
{
parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
result.flags |= ParseFlags.TimeZoneUsed;
result.timeZoneOffset = new TimeSpan(0L);
result.flags |= ParseFlags.TimeZoneUtc;
if (dtfi.Calendar.GetType() != typeof(GregorianCalendar))
{
dtfi = (DateTimeFormatInfo)dtfi.Clone();
dtfi.Calendar = GregorianCalendar.GetDefaultInstance();
goto IL_160;
}
goto IL_160;
}
}
parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
dtfi = DateTimeFormatInfo.InvariantInfo;
goto IL_160;
IL_65:
parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
dtfi = DateTimeFormatInfo.InvariantInfo;
if ((result.flags & ParseFlags.CaptureOffset) != (ParseFlags)0)
{
result.flags |= ParseFlags.Rfc1123Pattern;
}
IL_160:
return DateTimeFormat.GetRealFormat(format, dtfi);
}
示例4: ExpandPredefinedFormat
// Expand a pre-defined format string (like "D" for long date) to the real format that
// we are going to use in the date time parsing.
// This method also set the dtfi according/parseInfo to some special pre-defined
// formats.
//
private static String ExpandPredefinedFormat(String format, ref DateTimeFormatInfo dtfi, ref ParsingInfo parseInfo, ref DateTimeResult result) {
//
// Check the format to see if we need to override the dtfi to be InvariantInfo,
// and see if we need to set up the userUniversalTime flag.
//
switch (format[0]) {
case 'o':
case 'O': // Round Trip Format
parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
dtfi = DateTimeFormatInfo.InvariantInfo;
break;
case 'r':
case 'R': // RFC 1123 Standard. (in Universal time)
parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
dtfi = DateTimeFormatInfo.InvariantInfo;
if ((result.flags & ParseFlags.CaptureOffset) != 0) {
result.flags |= ParseFlags.Rfc1123Pattern;
}
break;
case 's': // Sortable format (in local time)
dtfi = DateTimeFormatInfo.InvariantInfo;
parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
break;
case 'u': // Universal time format in sortable format.
parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
dtfi = DateTimeFormatInfo.InvariantInfo;
if ((result.flags & ParseFlags.CaptureOffset) != 0) {
result.flags |= ParseFlags.UtcSortPattern;
}
break;
case 'U': // Universal time format with culture-dependent format.
parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
result.flags |= ParseFlags.TimeZoneUsed;
result.timeZoneOffset = new TimeSpan(0);
result.flags |= ParseFlags.TimeZoneUtc;
if (dtfi.Calendar.GetType() != typeof(GregorianCalendar)) {
dtfi = (DateTimeFormatInfo)dtfi.Clone();
dtfi.Calendar = GregorianCalendar.GetDefaultInstance();
}
break;
}
//
// Expand the pre-defined format character to the real format from DateTimeFormatInfo.
//
return (DateTimeFormat.GetRealFormat(format, dtfi));
}
示例5: ExpandPredefinedFormat
// Expand a pre-defined format string (like "D" for long date) to the real format that
// we are going to use in the date time parsing.
// This method also convert the dateTime if necessary (e.g. when the format is in Universal time),
// and change dtfi if necessary (e.g. when the format should use invariant culture).
//
private static String ExpandPredefinedFormat(String format, ref DateTime dateTime, ref DateTimeFormatInfo dtfi, ref TimeSpan offset) {
switch (format[0]) {
case 'o':
case 'O': // Round trip format
dtfi = DateTimeFormatInfo.InvariantInfo;
break;
case 'r':
case 'R': // RFC 1123 Standard
if (offset != NullOffset) {
// Convert to UTC invariants mean this will be in range
dateTime = dateTime - offset;
}
else if (dateTime.Kind == DateTimeKind.Local) {
InvalidFormatForLocal(format, dateTime);
}
dtfi = DateTimeFormatInfo.InvariantInfo;
break;
case 's': // Sortable without Time Zone Info
dtfi = DateTimeFormatInfo.InvariantInfo;
break;
case 'u': // Universal time in sortable format.
if (offset != NullOffset) {
// Convert to UTC invariants mean this will be in range
dateTime = dateTime - offset;
}
else if (dateTime.Kind == DateTimeKind.Local) {
InvalidFormatForLocal(format, dateTime);
}
dtfi = DateTimeFormatInfo.InvariantInfo;
break;
case 'U': // Universal time in culture dependent format.
if (offset != NullOffset) {
// This format is not supported by DateTimeOffset
throw new FormatException(Environment.GetResourceString("Format_InvalidString"));
}
// Universal time is always in Greogrian calendar.
//
// Change the Calendar to be Gregorian Calendar.
//
dtfi = (DateTimeFormatInfo)dtfi.Clone();
if (dtfi.Calendar.GetType() != typeof(GregorianCalendar)) {
dtfi.Calendar = GregorianCalendar.GetDefaultInstance();
}
dateTime = dateTime.ToUniversalTime();
break;
}
format = GetRealFormat(format, dtfi);
return (format);
}
示例6: ReadOnly
public static DateTimeFormatInfo ReadOnly(DateTimeFormatInfo dtfi)
{
DateTimeFormatInfo copy = (DateTimeFormatInfo)dtfi.Clone();
copy.m_isReadOnly = true;
return copy;
}
示例7: Build
internal static DateTimeFormatInfo Build(DateTimeFormatInfo original) {
var persianFormats = (DateTimeFormatInfo)original.Clone();
var persianCalendarMonthNames = new[] {
"فررودین",
"اردیبهشت",
"خرداد",
"تیر",
"مرداد",
"شهریور",
"مهر",
"آبان",
"آذر",
"دی",
"بهمن",
"اسفند",
"" // 13 months names always necessary...
};
persianFormats.MonthNames =
persianFormats.AbbreviatedMonthNames =
persianFormats.MonthGenitiveNames =
persianFormats.AbbreviatedMonthGenitiveNames =
persianCalendarMonthNames;
var persianDayNames = new[] {
"یکشنبه", // Changes the Arabic "ي" and "ك" to the Farsi "ی" and "ک" respectively (incorrect in .NET Framework).
"دوشنبه",
"سه شنبه",
"چهارشنبه",
"پنجشنبه",
"جمعه",
"شنبه"
};
persianFormats.DayNames =
persianFormats.AbbreviatedDayNames =
persianDayNames;
persianFormats.SetAllDateTimePatterns(new[] {
"yyyy/MM/dd",
"yy/MM/dd",
"yyyy/M/d",
"yy/M/d"
}, 'd');
persianFormats.SetAllDateTimePatterns(new[] {
"dddd، d MMMM yyyy",
"d MMMM yyyy"
}, 'D');
persianFormats.SetAllDateTimePatterns(new[] {
"MMMM yyyy",
"MMMM yy"
}, 'y');
persianFormats.SetAllDateTimePatterns(new[] {
"HH:mm",
"H:mm",
"hh:mm tt",
"h:mm tt"
}, 't');
persianFormats.SetAllDateTimePatterns(new[] {
"HH:mm:ss",
"H:mm:ss",
"hh:mm:ss tt",
"h:mm:ss tt"
}, 'T');
return persianFormats;
}
示例8: PosTest1
public void PosTest1()
{
DateTimeFormatInfo expected = new DateTimeFormatInfo();
VerificationHelper(expected, expected.Clone());
}
示例9: ConstructInvariant
private void ConstructInvariant (bool read_only)
{
cultureID = InvariantCultureId;
/* NumberFormatInfo defaults to the invariant data */
numInfo=NumberFormatInfo.InvariantInfo;
/* DateTimeFormatInfo defaults to the invariant data */
dateTimeInfo=DateTimeFormatInfo.InvariantInfo;
if (!read_only) {
numInfo = (NumberFormatInfo) numInfo.Clone ();
dateTimeInfo = (DateTimeFormatInfo) dateTimeInfo.Clone ();
}
textInfo = CreateTextInfo (read_only);
m_name=String.Empty;
displayname=
englishname=
nativename="Invariant Language (Invariant Country)";
iso3lang="IVL";
iso2lang="iv";
icu_name="en_US_POSIX";
win3lang="IVL";
}
示例10: ExpandPredefinedFormat
private static string ExpandPredefinedFormat(string format, ref DateTimeFormatInfo dtfi, ref ParsingInfo parseInfo, ref DateTimeResult result)
{
switch (format[0])
{
case 'o':
case 'O':
parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
dtfi = DateTimeFormatInfo.InvariantInfo;
break;
case 'r':
case 'R':
parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
dtfi = DateTimeFormatInfo.InvariantInfo;
if ((result.flags & ParseFlags.CaptureOffset) != 0)
{
result.flags |= ParseFlags.Rfc1123Pattern;
}
break;
case 's':
dtfi = DateTimeFormatInfo.InvariantInfo;
parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
break;
case 'u':
parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
dtfi = DateTimeFormatInfo.InvariantInfo;
if ((result.flags & ParseFlags.CaptureOffset) != 0)
{
result.flags |= ParseFlags.UtcSortPattern;
}
break;
case 'U':
parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
result.flags |= ParseFlags.TimeZoneUsed;
result.timeZoneOffset = new TimeSpan(0L);
result.flags |= ParseFlags.TimeZoneUtc;
if (dtfi.Calendar.GetType() != typeof(GregorianCalendar))
{
dtfi = (DateTimeFormatInfo) dtfi.Clone();
dtfi.Calendar = GregorianCalendar.GetDefaultInstance();
}
break;
}
return DateTimeFormat.GetRealFormat(format, dtfi);
}
示例11: ExpandPredefinedFormat
private static string ExpandPredefinedFormat(string format, ref DateTime dateTime, ref DateTimeFormatInfo dtfi, ref TimeSpan offset)
{
char c = format[0];
if (c <= 'R')
{
if (c != 'O')
{
if (c != 'R')
{
goto IL_160;
}
goto IL_5A;
}
}
else
{
if (c != 'U')
{
switch (c)
{
case 'o':
{
break;
}
case 'p':
case 'q':
case 't':
{
goto IL_160;
}
case 'r':
{
goto IL_5A;
}
case 's':
{
dtfi = DateTimeFormatInfo.InvariantInfo;
goto IL_160;
}
case 'u':
{
if (offset != DateTimeFormat.NullOffset)
{
dateTime -= offset;
}
else
{
if (dateTime.Kind == DateTimeKind.Local)
{
DateTimeFormat.InvalidFormatForLocal(format, dateTime);
}
}
dtfi = DateTimeFormatInfo.InvariantInfo;
goto IL_160;
}
default:
{
goto IL_160;
}
}
}
else
{
if (offset != DateTimeFormat.NullOffset)
{
throw new FormatException(Environment.GetResourceString("Format_InvalidString"));
}
dtfi = (DateTimeFormatInfo)dtfi.Clone();
if (dtfi.Calendar.GetType() != typeof(GregorianCalendar))
{
dtfi.Calendar = GregorianCalendar.GetDefaultInstance();
}
dateTime = dateTime.ToUniversalTime();
goto IL_160;
}
}
dtfi = DateTimeFormatInfo.InvariantInfo;
goto IL_160;
IL_5A:
if (offset != DateTimeFormat.NullOffset)
{
dateTime -= offset;
}
else
{
if (dateTime.Kind == DateTimeKind.Local)
{
DateTimeFormat.InvalidFormatForLocal(format, dateTime);
}
}
dtfi = DateTimeFormatInfo.InvariantInfo;
IL_160:
format = DateTimeFormat.GetRealFormat(format, dtfi);
return format;
}
示例12: ExpandPredefinedFormat
// Expand a pre-defined format string (like "D" for long date) to the real format that
// we are going to use in the date time parsing.
// This method also convert the dateTime if necessary (e.g. when the format is in Universal time),
// and change dtfi if necessary (e.g. when the format should use invariant culture).
//
private static String ExpandPredefinedFormat(String format, ref DateTime dateTime, ref DateTimeFormatInfo dtfi) {
switch (format[0]) {
case 'o':
case 'O': // Round trip format
dtfi = DateTimeFormatInfo.InvariantInfo;
break;
case 'r':
case 'R': // RFC 1123 Standard
if (dateTime.Kind == DateTimeKind.Local) {
InvalidFormatForLocal(format, dateTime);
}
dtfi = DateTimeFormatInfo.InvariantInfo;
break;
case 's': // Sortable without Time Zone Info
dtfi = DateTimeFormatInfo.InvariantInfo;
break;
case 'u': // Universal time in sortable format.
if (dateTime.Kind == DateTimeKind.Local) {
InvalidFormatForLocal(format, dateTime);
}
dtfi = DateTimeFormatInfo.InvariantInfo;
break;
case 'U': // Universal time in culture dependent format.
// Universal time is always in Greogrian calendar.
//
// Change the Calendar to be Gregorian Calendar.
//
dtfi = (DateTimeFormatInfo)dtfi.Clone();
if (dtfi.Calendar.GetType() != typeof(GregorianCalendar)) {
dtfi.Calendar = GregorianCalendar.GetDefaultInstance();
}
dateTime = dateTime.ToUniversalTime();
break;
}
format = GetRealFormat(format, dtfi);
return (format);
}
示例13: ExpandPredefinedFormat
// Expand a pre-defined format string (like "D" for long date) to the real format that
// we are going to use in the date time parsing.
// This method also set the dtfi according/parseInfo to some special pre-defined
// formats.
//
private static String ExpandPredefinedFormat(String format, ref DateTimeFormatInfo dtfi, ParsingInfo parseInfo) {
//
// Check the format to see if we need to override the dtfi to be InvariantInfo,
// and see if we need to set up the userUniversalTime flag.
//
switch (format[0]) {
case 'r':
case 'R': // RFC 1123 Standard. (in Universal time)
parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
dtfi = DateTimeFormatInfo.InvariantInfo;
break;
case 's': // Sortable format (in local time)
dtfi = DateTimeFormatInfo.InvariantInfo;
parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
break;
case 'u': // Universal time format in sortable format.
parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
dtfi = DateTimeFormatInfo.InvariantInfo;
break;
case 'U': // Universal time format with culture-dependent format.
parseInfo.calendar = GregorianCalendar.GetDefaultInstance();
parseInfo.fUseUniversalTime = true;
if (dtfi.Calendar.GetType() != typeof(GregorianCalendar)) {
dtfi = (DateTimeFormatInfo)dtfi.Clone();
dtfi.Calendar = GregorianCalendar.GetDefaultInstance();
}
break;
}
//
// Expand the pre-defined format character to the real format from DateTimeFormatInfo.
//
return (DateTimeFormat.GetRealFormat(format, dtfi));
}
示例14: ReadOnly
// Create a read-only copy of a DateTimeFormatInfo object.
public static DateTimeFormatInfo ReadOnly(DateTimeFormatInfo dtfi)
{
if(dtfi == null)
{
throw new ArgumentNullException("dtfi");
}
else if(dtfi.IsReadOnly)
{
return dtfi;
}
else
{
DateTimeFormatInfo newDtfi;
newDtfi = (DateTimeFormatInfo)(dtfi.Clone());
newDtfi.readOnly = true;
return newDtfi;
}
}