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


C# DateTime.ToShortDateString方法代码示例

本文整理汇总了C#中DateTime.ToShortDateString方法的典型用法代码示例。如果您正苦于以下问题:C# DateTime.ToShortDateString方法的具体用法?C# DateTime.ToShortDateString怎么用?C# DateTime.ToShortDateString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DateTime的用法示例。


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

示例1: ParsePair

            private void ParsePair( string input )
            {
                input = input.Replace( "\"", "" ).Replace( "\\", "" ).Replace( "%", "" );
                int dashIndex = input.IndexOf( "-" );
                string s1 = input.Substring( 0, dashIndex ), s2 = input.Substring( dashIndex + 1 );
                if ( s1.Length > 3 && !s1.Contains( "N/A" ) )
                {
                    if ( input.Contains( "pm" ) || input.Contains( "am" ) )
                    {
                        int endIndex = input.Contains( "pm" ) ? input.IndexOf( "pm" ) : input.IndexOf( "am" );
                        string tempSubstring = input.Substring( 0, endIndex );
                        int colonIndex = tempSubstring.IndexOf( ":" );
                        int hour = Int32.Parse( tempSubstring.Substring( 0, colonIndex ).Replace( "-", "" ) ), minutes = Int32.Parse( tempSubstring.Substring( colonIndex + 1 ).Replace( "-", "" ) );
                        // Add time of day
                        DateTime dt = new DateTime( DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, hour, minutes, 0 );
                        _data = dt;
                        _str = dt.Hour.ToString( ) + ":" + ( dt.Minute.ToString( ).Length == 2 ? dt.Minute.ToString( ) : "0" + dt.Minute.ToString( ) );

                        return;
                    }
                    else
                    {
                        int spaceIndex = s1.IndexOf( " " );
                        string sub1 = s1.Substring( 0, spaceIndex ).Replace( " ", "" ), sub2 = s1.Substring( spaceIndex + 1 ).Replace( " ", "" );
                        int month = MonthMap [ sub1 ], day = Int16.Parse( sub2 ), year = DateTime.Now.Year;
                        DateTime dt = new DateTime( year, month, day );
                        decimal? i2 = Decimal.Parse( s2.Replace( "<b>", "" ).Replace( "</b>", "" ).Replace( " ", "" ) );
                        _data = new Tuple<DateTime?, decimal?>( dt, i2 );
                        _str = dt.ToShortDateString( ) + ": " + i2.ToString( );
                        var xgonGive = 1;
                        return;
                    }

                }
                else
                {
                    decimal? i2 = Decimal.Parse( s2.Replace( "<b>", "" ).Replace( "</b>", "" ).Replace( " ", "" ) );
                    _data = new Tuple<DateTime?, decimal?>( null, i2 );
                    _str = "N/A"+ ": " + i2.ToString( );
                }

                return;
            }
开发者ID:kamalm87,项目名称:KNMFin,代码行数:43,代码来源:Companies.cs

示例2: IsDateTimeDefaultTests

 public void IsDateTimeDefaultTests(string culture)
 {
     using (new CultureReplacer(culture))
     {
         var dateTime = new DateTime(2011, 10, 25, 10, 10, 00);
         Assert.True(dateTime.ToShortDateString().IsDateTime());
         Assert.True(dateTime.ToString().IsDateTime());
         Assert.True(dateTime.ToLongDateString().IsDateTime());
     }
 }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:10,代码来源:StringExtensionsTest.cs

示例3: CreateAirfareSearchUri

 /// <summary>
 /// Creates a Uri to look up flight pricing trends online using Bing
 /// Travel.
 /// </summary>
 /// <param name="departureAirport">The departure airport object.</param>
 /// <param name="arrivalAirport">The arrival airport object.</param>
 /// <param name="departure">The departure date.</param>
 /// <param name="arrival">The arrival date.</param>
 /// <param name="persons">The number of people that will be traveling.</param>
 /// <returns>Returns a new Uri object.</returns>
 public static Uri CreateAirfareSearchUri(Airport departureAirport, Airport arrivalAirport, DateTime departure, DateTime arrival, int persons)
 {
     return new Uri(string.Format(CultureInfo.InvariantCulture, AirfareSearchUriFormat, departureAirport.CodeFaa, arrivalAirport.CodeFaa, HttpUtility.UrlEncode(departure.ToShortDateString()), HttpUtility.UrlEncode(arrival.ToShortDateString()), persons.ToString(CultureInfo.InvariantCulture)));
 }
开发者ID:jira-sarec,项目名称:ICSE-2012-TraceLab,代码行数:14,代码来源:WebServiceHelper.cs


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