• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# DateTimeStyles类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: TryParsDateTimeExact

        /// <summary>
        ///     Converts the specified string representation of a date and time to its DateTime equivalent using the specified
        ///     format,
        ///     culture-specific format information, and style.
        ///     The format of the string representatiomust match the specified format exactly.
        ///     The method returns a value that indicates whether the conversion succeeded.
        /// </summary>
        /// <exception cref="ArgumentNullException">value can not be null.</exception>
        /// <exception cref="ArgumentNullException">format can not be null.</exception>
        /// <exception cref="ArgumentNullException">format provider can not be null.</exception>
        /// <param name="value">A <see cref="String" /> containing a date and time to convert.</param>
        /// <param name="format">The required format of s. See the Remarks section for more information.</param>
        /// <param name="formatProvider">
        ///     An object that supplies culture-specific formatting information about
        ///     <paramref name="value" />.
        /// </param>
        /// <param name="dateTimeStyle">
        ///     A bitwise combination of one or more enumeration values that indicate the permitted format
        ///     of <paramref name="value" />.
        /// </param>
        /// <param name="outValue">
        ///     When this method returns, contains the s<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 either the s or format parameter is null, is an empty string, or does not contain a date
        ///     and time that correspond to the pattern specified in format.
        ///     This parameter is passed uninitialized.
        /// </param>
        /// <returns>Returns true if the parsing was successful, otherwise false.</returns>
        public static Boolean TryParsDateTimeExact( this String value,
                                                    String format,
                                                    IFormatProvider formatProvider,
                                                    DateTimeStyles dateTimeStyle,
                                                    out DateTime outValue )
        {
            value.ThrowIfNull( nameof( value ) );
            format.ThrowIfNull( nameof( format ) );
            formatProvider.ThrowIfNull( nameof( formatProvider ) );

            return DateTime.TryParseExact( value, format, formatProvider, dateTimeStyle, out outValue );
        }
开发者ID:MannusEtten,项目名称:Extend,代码行数:41,代码来源:String.TryParsDateTimeExact.cs


示例17: FromParsedDate

        /// <summary>
        /// Convert from java based date to DateTime.
        /// </summary>
        private static DateTime FromParsedDate(Date value, string originalString, DateTimeStyles style, DateFormat formatter, bool forceRoundtripKind, bool useUtc)
        {
            bool assumeLocal = (style & DateTimeStyles.AssumeLocal) != 0;
            bool assumeUtc = useUtc || (style & DateTimeStyles.AssumeUniversal) != 0;
            bool roundtripKind = forceRoundtripKind || (style & DateTimeStyles.RoundtripKind) != 0;

            var millis = value.Time;
            var ticks = (millis + DateTime.EraDifferenceInMs) * TimeSpan.TicksPerMillisecond;

            //long offset = 0L;
            DateTimeKind kind;

            if (roundtripKind)
            {
                var tz = formatter.TimeZone;
                if(tz.RawOffset == 0 || originalString.EndsWith("Z"))
                    kind = DateTimeKind.Utc;
                else if(tz.RawOffset == TimeZone.Default.RawOffset)
                    kind = DateTimeKind.Local;
                else
                    kind = DateTimeKind.Unspecified;
            }
            else if (assumeUtc)
            {
                kind = DateTimeKind.Utc;
            }
            else if (assumeLocal)
            {
                kind = DateTimeKind.Local;
            }
            else
            {
                kind = DateTimeKind.Unspecified;
            }

            DateTime result;

            if (millis == DateTime.MinValueJavaMillies)
                result = new DateTime(0L, kind);
            else
            {
                result = new DateTime(ticks, kind);
            }


            if ((style & DateTimeStyles.AdjustToUniversal) != 0)
                result = result.ToUniversalTime();
            else if (assumeUtc) // no typo, but bad naming/semantics in the BCL
                result = result.ToLocalTime();

            return result;
        }
开发者ID:sebastianhaba,项目名称:api,代码行数:55,代码来源:DateTimeParsing.cs


示例18: SaveToDateTime

        /// <summary>
        ///     Converts the given string to a date time value.
        /// </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">The string to convert.</param>
        /// <param name="formatProvider">The format provider.</param>
        /// <param name="dateTimeStyle">The date time style.</param>
        /// <param name="defaultValue">The default value, returned if the parsing fails.</param>
        /// <returns>The date time value.</returns>
        public static DateTime SaveToDateTime( this String value,
                                               IFormatProvider formatProvider,
                                               DateTimeStyles dateTimeStyle,
                                               DateTime? defaultValue = null )
        {
            value.ThrowIfNull( nameof( value ) );
            formatProvider.ThrowIfNull( nameof( formatProvider ) );

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


示例19: TryParseExact

 internal static bool TryParseExact(String s, String format, IFormatProvider provider, DateTimeStyles style, out DateTime result)
 {
     DateTimeFormatInfo dtfi = provider == null ? DateTimeFormatInfo.CurrentInfo : DateTimeFormatInfo.GetInstance(provider);
     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:noahfalk,项目名称:corert,代码行数:13,代码来源:FormatProvider.DateTimeParse.cs


示例20: TryParse

 public static bool TryParse(string s, DateTimeFormatInfo dateTimeFormatInfo, DateTimeStyles dateTimeStyles, out SystemDateTime dateTime)
 {
     try
     {
         dateTime = SystemDateTime.Parse(s, dateTimeFormatInfo, dateTimeStyles);
         return true;
     }
     catch (FormatException)
     {
         dateTime = SystemDateTime.MinValue;
         return false;
     }
 }
开发者ID:thekindofme,项目名称:.netcf-Validation-Framework,代码行数:13,代码来源:DateTimeParser.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# DateTimeZoneHandling类代码示例发布时间:2022-05-24
下一篇:
C# DateTimeRange类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap