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


C# DateTimeStyles类代码示例

本文整理汇总了C#中DateTimeStyles的典型用法代码示例。如果您正苦于以下问题:C# DateTimeStyles类的具体用法?C# DateTimeStyles怎么用?C# DateTimeStyles使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DateTimeStyles类属于命名空间,在下文中一共展示了DateTimeStyles类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InitializeMembers

 private void InitializeMembers()
 {
     this.encoding = null;
     this.culture = null;
     this.numberStyle = NumberStyles.Float;
     this.dateTimeStyle = DateTimeStyles.None;
 }
开发者ID:horvatferi,项目名称:graywulf,代码行数:7,代码来源:FormattedDataFile.cs

示例2: ParseExact

        public static DateTime ParseExact(string s, string format, IFormatProvider provider, DateTimeStyles style)
        {
            // Note: the Date/Time handling in java is just broken, and putting a 
            //       .NET compatibility layer on top of it will probalby not fix much
            if (s == null || format == null)
                throw new ArgumentNullException();

            if ((style & DateTimeStyles.AllowLeadingWhite) != 0)
                s = s.TrimStart();
            if ((style & DateTimeStyles.AllowTrailingWhite) != 0)
                s = s.TrimEnd();
            if ((style & DateTimeStyles.AllowWhiteSpaces) != 0)
                s = s.Trim();

            try
            {
                var formatter = DateFormatFactory.GetFormat(format, DateTimeKind.Unspecified, provider);
                formatter.Format.TimeZone = TimeZone.GetTimeZone("UTC"); // reset mutable value

                Date parsed = formatter.Format.Parse(s);

                var result = FromParsedDate(parsed, s, style, formatter.Format, formatter.ContainsK, formatter.UseUtc);
                return result;
            }
            catch (ArgumentException ex)
            {
                throw new FormatException(ex.Message);
            }
            catch (ParseException ex)
            {
                throw new ArgumentException(ex.Message, "s");
            }
        }
开发者ID:sebastianhaba,项目名称:api,代码行数:33,代码来源:DateTimeParsing.cs

示例3: GlobalizationConfiguration

        /// <summary>
        /// Initializes a new instance of the <see cref="GlobalizationConfiguration"/> class
        /// </summary>
        /// <param name="supportedCultureNames">An array of supported cultures</param>
        /// <param name="defaultCulture">The default culture of the application</param>
        /// <param name="dateTimeStyles">The <see cref="DateTimeStyles"/> that should be used for date parsing.</param>
        public GlobalizationConfiguration(IEnumerable<string> supportedCultureNames, string defaultCulture = null, DateTimeStyles? dateTimeStyles = null)
        {
            if (supportedCultureNames == null)
            {
                throw new ConfigurationException("Invalid Globalization configuration. You must support at least one culture");
            }

            supportedCultureNames = supportedCultureNames.Where(cultureName => !string.IsNullOrEmpty(cultureName)).ToArray();

            if (!supportedCultureNames.Any())
            {
                throw new ConfigurationException("Invalid Globalization configuration. You must support at least one culture");
            }

            if (string.IsNullOrEmpty(defaultCulture))
            {
                defaultCulture = supportedCultureNames.First();
            }

            if (!supportedCultureNames.Contains(defaultCulture, StringComparer.OrdinalIgnoreCase))
            {
                throw new ConfigurationException("Invalid Globalization configuration. " + defaultCulture + " does not exist in the supported culture names");
            }

            this.DateTimeStyles = dateTimeStyles ?? Default.DateTimeStyles;
            this.DefaultCulture = defaultCulture;
            this.SupportedCultureNames = supportedCultureNames;
        }
开发者ID:RadifMasud,项目名称:Nancy,代码行数:34,代码来源:GlobalizationConfiguration.cs

示例4: TryParseDate

        /// <summary>
        /// Convert string date to datetime
        /// </summary>
        /// <param name="strValue">string to convert</param>
        /// <param name="defaultValue">default value when invalid date</param>
        /// <param name="culture">date culture</param>
        /// <param name="dateTimeStyle">datetime style</param>
        /// <returns>datetime</returns>
        public static DateTime TryParseDate(this string strValue, DateTime defaultValue, CultureInfo culture, DateTimeStyles dateTimeStyle)
        {
            DateTime date;
            if (DateTime.TryParse(strValue, culture, dateTimeStyle, out date))
                return date;

            #region FromOADate
            if (strValue.IsValidDouble(NumberStyles.Float, culture))
            {
                var doubleValue = strValue.TryParseDouble(-99);
                if (doubleValue >= -657434.999 && doubleValue <= 2593589)
                {
                    try
                    {
                        return DateTime.FromOADate(doubleValue);
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e);
                    }
                }
            } 
            #endregion
            
            return defaultValue;
        }
开发者ID:jornfilho,项目名称:.net-Dev-Utils,代码行数:34,代码来源:DateExtensions.cs

示例5: Globalization

 /// <summary>
 /// Configures <see cref="GlobalizationConfiguration"/>
 /// </summary>
 /// <param name="environment">An <see cref="INancyEnvironment"/> that should be configured.</param>
 /// <param name="supportedCultureNames">Cultures that the application can accept</param>
 /// <param name="defaultCulture">Used to set a default culture for the application</param>
 /// <param name="dateTimeStyles">The <see cref="DateTimeStyles"/> that should be used for date parsing.</param>
 /// <remarks>If defaultCulture not specified the first supported culture is used</remarks>
 public static void Globalization(this INancyEnvironment environment, IEnumerable<string> supportedCultureNames, string defaultCulture = null, DateTimeStyles? dateTimeStyles = null)
 {
     environment.AddValue(new GlobalizationConfiguration(
         supportedCultureNames: supportedCultureNames,
         defaultCulture: defaultCulture,
         dateTimeStyles: dateTimeStyles));
 }
开发者ID:RadifMasud,项目名称:Nancy,代码行数:15,代码来源:GlobalizationConfigurationExtensions.cs

示例6: DateParser

        public DateParser(string format, DateTimeKind kind)
        {
            switch (kind)
            {
                case DateTimeKind.Local:
                    _style = DateTimeStyles.AssumeLocal;
                    break;

                case DateTimeKind.Utc:
                    _style = DateTimeStyles.AssumeUniversal;
                    break;

                default:
                    throw new ArgumentOutOfRangeException("kind");
            }

            switch (format)
            {
                case "ABSOLUTE":
                    break;

                case "ISO8601":
                    break;

                case "DATE":
                    break;
            }
        }
开发者ID:Kittyfisto,项目名称:Tailviewer,代码行数:28,代码来源:DateParser.cs

示例7: DateTime

        internal static readonly long TicksAt1970 = 621355968000000000L; //new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks;

        /// <summary>
        /// Parses string in following formats to DateTime representation:
        ///  - @[email protected] - 1970-01-01 + decimal (millisec) - UTC!
        ///  - \/Date(decimal)\/ - 1970-01-01 + decimal (millisec) - UTC!
        ///  - \/Date(yyyy,MM,dd[,hh,mm,ss,mmm])\/ - direct params - UTC!
        ///  - decimal - 1970-01-01 + decimal (millisec/sec) - UTC!
        ///  - ISO format - with time zones support
        /// </summary>
        public static DateTime ParseDateTime(string text, IFormatProvider provider, DateTimeStyles styles, JSonDateTimeKind kind)
        {
            if (!String.IsNullOrEmpty(text))
            {
                var date = text.Replace(" ", String.Empty).Replace("\t", String.Empty);

                if (date.Length > 2)
                {
                    if (date[0] == '@' && date[date.Length - 1] == '@')
                        return ParseDateTimeAsDecimal(date.Substring(1, date.Length - 2));

                    if (date.StartsWith("\\/Date(", StringComparison.OrdinalIgnoreCase) && date.EndsWith(")\\/"))
                        return ParseDateTimeAsArrayOfDecimals(date.Substring(7, date.Length - 10));

                    if (date.StartsWith("/Date(", StringComparison.OrdinalIgnoreCase) && date.EndsWith(")/"))
                        return ParseDateTimeAsArrayOfDecimals(date.Substring(6, date.Length - 8));
                }
            }

            // try to parse date as a pure number:
            long dateValue;
            if (NumericHelper.TryParseInt64(text, out dateValue))
                return ToDateTime(dateValue, kind);

            // always try to parse as ISO format, to get the result or throw a standard exception, when non-matching format given:
            return DateTime.Parse(text, provider, styles);
        }
开发者ID:phofman,项目名称:codetitans-libs,代码行数:37,代码来源:DateTimeHelper.cs

示例8: DateTimeOffsetTryParseNullable

        public static DateTimeOffset? DateTimeOffsetTryParseNullable(string value, IFormatProvider provider, DateTimeStyles styles)
        {
            DateTimeOffset result;
            if (!DateTimeOffset.TryParse(value, provider, styles, out result))
                return null;

            return result;
        }
开发者ID:brennanfee,项目名称:FluentConversions,代码行数:8,代码来源:DateTimeStringParser.cs

示例9: DeserializeObject

        /// <summary>
        /// Deserialize an object
        /// </summary>
        /// <param name="value">The object to deserialize</param>
        /// <param name="type">The type of object to deserialize</param>
        /// <param name="dateTimeStyles">The <see cref="DateTimeStyles"/> ton convert <see cref="DateTime"/> objects</param>
        /// <returns>A instance of <paramref name="type" /> deserialized from <paramref name="value"/></returns>
        public override object DeserializeObject(object value, Type type, DateTimeStyles dateTimeStyles)
        {
            var typeInfo = type.GetTypeInfo();
            if (typeInfo.IsEnum || (ReflectionUtils.IsNullableType(type) && Nullable.GetUnderlyingType(type).GetTypeInfo().IsEnum))
            {
                var typeToParse = ReflectionUtils.IsNullableType(type)
                    ? Nullable.GetUnderlyingType(type)
                    : type;

                return value == null
                    ? null
                    : Enum.Parse(typeToParse, value.ToString(), true);
            }

            var primitiveConverter = this.FindPrimitiveConverter(type);
            if (primitiveConverter != null)
            {
                return primitiveConverter.Deserialize(value, type);
            }

            var valueDictionary = value as IDictionary<string, object>;
            if (valueDictionary == null)
            {
                return base.DeserializeObject(value, type, dateTimeStyles);
            }

            var javascriptConverter = this.FindJavaScriptConverter(type);
            if (javascriptConverter != null)
            {
                return javascriptConverter.Deserialize(valueDictionary, type);
            }

            if (!typeInfo.IsGenericType)
            {
                return base.DeserializeObject(value, type, dateTimeStyles);
            }

            var genericType = typeInfo.GetGenericTypeDefinition();
            var genericTypeConverter = this.FindJavaScriptConverter(genericType);

            if (genericTypeConverter == null)
            {
                return base.DeserializeObject(value, type, dateTimeStyles);
            }

            var values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
            var genericArguments = type.GetGenericArguments();

            for (var i = 0; i < genericArguments.Length; i++)
            {
                var deserializedObject = this.DeserializeObject(valueDictionary.Values.ElementAt(i),
                    genericArguments[i], dateTimeStyles);

                values.Add(valueDictionary.Keys.ElementAt(i), deserializedObject);
            }

            return genericTypeConverter.Deserialize(values, type);
        }
开发者ID:cemremengu,项目名称:Nancy,代码行数:65,代码来源:NancySerializationStrategy.cs

示例10: DateTimeOffsetTryParseExactNullable

        public static DateTimeOffset? DateTimeOffsetTryParseExactNullable(
            string value, IEnumerable<string> formats, IFormatProvider provider, DateTimeStyles styles)
        {
            DateTimeOffset result;
            if (!DateTimeOffset.TryParseExact(value, formats.ToArray(), provider, styles, out result))
                return null;

            return result;
        }
开发者ID:brennanfee,项目名称:FluentConversions,代码行数:9,代码来源:DateTimeStringParser.cs

示例11: IsDate

 public static bool IsDate(string date, string format, IFormatProvider provider, DateTimeStyles styles)
 {
     if (string.IsNullOrEmpty(date))
     {
         return false;
     }
     DateTime minValue = DateTime.MinValue;
     return DateTime.TryParseExact(date, format, provider, styles, out minValue);
 }
开发者ID:applenele,项目名称:SmallCode,代码行数:9,代码来源:RegexHelper.cs

示例12: StateByName

 /// <remarks>
 /// This method uses the
 /// <see cref="DateTime.Parse(string,IFormatProvider,DateTimeStyles)"/>
 /// method to convert the "state" into its <see cref="Guid"/>. Exceptions
 /// throwed by this method will be propagated to the caller.
 /// </remarks>
 public virtual bool StateByName(string name, DateTimeStyles styles,
   out DateTime state) {
   string s;
   if (StateByName(name, out s)) {
     state = DateTime.Parse(s, null, styles);
     return true;
   }
   state = DateTime.MinValue;
   return false;
 }
开发者ID:joethinh,项目名称:nohros-must,代码行数:16,代码来源:AbstractStateDao.cs

示例13: ParseExact

 internal static DateTime ParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style) {
     DateTimeResult result = new DateTimeResult();       // The buffer to store the parsing result.
     result.Init();
     if (TryParseExact(s, format, dtfi, style, ref result)) {
         return result.parsedDate;
     }
     else {
         throw GetDateTimeParseException(ref result);
     }
 }
开发者ID:ChuangYang,项目名称:coreclr,代码行数:10,代码来源:DateTimeParse.cs

示例14: TryParseExact

 internal static bool TryParseExact(String s, String format, DateTimeFormatInfo dtfi, DateTimeStyles style, out DateTime result) {
     result = DateTime.MinValue;
     DateTimeResult resultData = new DateTimeResult();       // The buffer to store the parsing result.
     resultData.Init();
     if (TryParseExact(s, format, dtfi, style, ref resultData)) {
         result = resultData.parsedDate;
         return true;
     }
     return false;
 }
开发者ID:ChuangYang,项目名称:coreclr,代码行数:10,代码来源:DateTimeParse.cs

示例15: TryParsDateTime

        /// <summary>
        ///     Converts the specified string representation of a date and time to its <see cref="DateTime" /> equivalent using the
        ///     specified culture-specific format information and formatting style, and returns a value that indicates whether the
        ///     conversion succeeded.
        /// </summary>
        /// <exception cref="ArgumentNullException">The value can not be null.</exception>
        /// <exception cref="ArgumentNullException">The format provider can not be null.</exception>
        /// <param name="value">A <see cref="String" /> containing a date and time to convert.</param>
        /// <param name="formatProvider">
        ///     An object that supplies culture-specific formatting information about
        ///     <paramref name="value" />.
        /// </param>
        /// <param name="dateTimeStyle">
        ///     A bitwise combination of enumeration values that defines how to interpret the parsed date in relation to the
        ///     current time zone or the current date.
        ///     A typical value to specify is <see cref="DateTimeStyles.None" />.
        /// </param>
        /// <param name="result">
        ///     When this method returns, contains the <see cref="DateTime" /> value equivalent to the date and time contained in
        ///     <paramref name="value" />, if the conversion succeeded, or
        ///     <see cref="DateTime.MinValue" /> if the conversion failed. The conversion fails if the <paramref name="value" />
        ///     parameter is
        ///     <value>null</value>
        ///     , is an empty string (""),
        ///     or does not contain a valid string representation of a date and time. This parameter is passed uninitialized.
        /// </param>
        /// <returns>
        ///     <value>true</value>
        ///     if the s parameter was converted successfully; otherwise,
        ///     <value>false</value>
        ///     .
        /// </returns>
        public static Boolean TryParsDateTime( this String value,
                                               IFormatProvider formatProvider,
                                               DateTimeStyles dateTimeStyle,
                                               out DateTime result )
        {
            value.ThrowIfNull( nameof( value ) );
            formatProvider.ThrowIfNull( nameof( formatProvider ) );

            return DateTime.TryParse( value, formatProvider, dateTimeStyle, out result );
        }
开发者ID:MannusEtten,项目名称:Extend,代码行数:42,代码来源:String.TryParsDateTime.cs


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