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


C# DateTime.Equals方法代码示例

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


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

示例1: CompareDate

        public static bool CompareDate(DateTime dateToCompare, DateTime date, int minuteTolerance)
        {
            if (!dateToCompare.Equals(date))
            {
                date = date.AddMinutes(minuteTolerance);

                if (!dateToCompare.Equals(date))
                {
                    date = date.AddMinutes(-2 * minuteTolerance);

                    if (!dateToCompare.Equals(date))
                    {
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }
                else
                {
                    return true;
                }
            }
            else
            {
                return true;
            }
        }
开发者ID:skiel85,项目名称:taller-desarrollo-proyectos-i,代码行数:29,代码来源:DateTimeComparer.cs

示例2: Workdays

    static int Workdays(DateTime inputDate)
    {
        DateTime today = new DateTime();
        today = DateTime.Today;
        DateTime [] hollidays = 
        { 
            new DateTime(2013,5,1),   
            new DateTime(2013,5,2),
            new DateTime(2013,5,3),
            new DateTime(2013,5,6),
            new DateTime(2013,5,24),
            new DateTime(2013,9,6),
            new DateTime(2013,12,24),
            new DateTime(2013,12,25),
            new DateTime(2013,12,26)
        };
        
        bool isWorkday = true;
        int countWorkdays = 0;
        today = today.AddDays(1);
        while (today.Equals(inputDate) == false)
        {
            string day = today.DayOfWeek.ToString();
            if (day.CompareTo("Sunday") == 0 || day.CompareTo("Saturday") == 0)
            {
                isWorkday = false;
            }

            if (isWorkday)
            {
                foreach (var date in hollidays)
                {
                    if (today.Equals(date))
                    {
                        isWorkday = false;
                        break;
                    }
                }
            }

            if (isWorkday)
            {
                countWorkdays++;
            }

            else
            {
                isWorkday = true;
            }

            today = today.AddDays(1);
        }

        return countWorkdays;
    }
开发者ID:Jarolim,项目名称:AllMyHomeworkForTelerikAcademy,代码行数:55,代码来源:CalculateWorkdays.cs

示例3: GetDateString

 /// <summary>
 /// 时间显示格式处理
 /// </summary>
 /// <param name="d">时间值</param>
 /// <param name="format">格式字符串。</param>
 /// <returns></returns>
 public static string GetDateString(DateTime d, string format)
 {
     if (d == null || d.ToString() == "" || d.Equals(Utils.GetDateTime("1900-1-1 0:00:00")) || d.Equals(Utils.GetDateTime("0001-01-01 0:00:00")))
     {
         return "";
     }
     else
     {
         return d.ToString(format);
     }
 }
开发者ID:uwitec,项目名称:O2O,代码行数:17,代码来源:UtilsCommons.cs

示例4: CanConvertBothDirections

        public void CanConvertBothDirections()
        {
            var now = DateTime.UtcNow;

            var nowWithoutMs = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second,
                                            now.Millisecond, DateTimeKind.Utc);
            var rightNow = now.ToMillisecondTimestamp().ToDateTime();

            Assert.IsTrue(nowWithoutMs.Equals(rightNow));

            var yesterday = (nowWithoutMs.ToMillisecondTimestamp() - (long)TimeSpan.FromDays(1).TotalMilliseconds).ToDateTime();
            var dayAfterTomorrow = yesterday.AddDays(1);

            Assert.IsTrue(nowWithoutMs.Equals(dayAfterTomorrow.ToUniversalTime()));
        }
开发者ID:darting,项目名称:MetricSystem,代码行数:15,代码来源:DateTimeExtensionMethodTests.cs

示例5: TakeScreenshot

        /// <summary>
        /// Method to take screenshot from primary screen, change it's creation time and save it into the folder
        /// </summary>
        /// <param name="creationTime"></param>
        /// <param name="screenPath"></param>
        /// <returns></returns>
        public static string TakeScreenshot(DateTime creationTime = default(DateTime), string screenPath = "")
        {
            var format = ImageFormat.Png;
            var now = DateTime.Now;
            creationTime = creationTime.Equals(default(DateTime)) ? now : creationTime;
            var screenName = GetScreenName(creationTime, format);

            using (var bmpScreenCapture = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
                                            Screen.PrimaryScreen.Bounds.Height))
            {
                using (var g = Graphics.FromImage(bmpScreenCapture))
                {
                    g.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
                                     Screen.PrimaryScreen.Bounds.Y,
                                     0, 0,
                                     bmpScreenCapture.Size,
                                     CopyPixelOperation.SourceCopy);

                    var file = (screenPath.Equals("") ? GetPath() : screenPath) + screenName;
                    bmpScreenCapture.Save(file, format);
                    var fileInfo = new FileInfo(file);
                    fileInfo.Refresh();
                    fileInfo.CreationTime = creationTime;

                }
            }
            return screenName;
        }
开发者ID:elv1s42,项目名称:ScreenshotTaker,代码行数:34,代码来源:Taker.cs

示例6: IsPublicHoliday

        static bool IsPublicHoliday(DateTime date)
        {
            bool isHoliday = false;

            List<DateTime> publicHolidaysList = new List<DateTime>();

            publicHolidaysList.Add(Convert.ToDateTime("1.1.2015"));
            publicHolidaysList.Add(Convert.ToDateTime("2.1.2015"));
            publicHolidaysList.Add(Convert.ToDateTime("3.3.2015"));
            publicHolidaysList.Add(Convert.ToDateTime("10.4.2015"));
            publicHolidaysList.Add(Convert.ToDateTime("13.4.2015"));
            publicHolidaysList.Add(Convert.ToDateTime("1.5.2015"));
            publicHolidaysList.Add(Convert.ToDateTime("6.5.2015"));
            publicHolidaysList.Add(Convert.ToDateTime("24.5.2015"));
            publicHolidaysList.Add(Convert.ToDateTime("6.9.2015"));
            publicHolidaysList.Add(Convert.ToDateTime("22.9.2015"));
            publicHolidaysList.Add(Convert.ToDateTime("24.12.2015"));
            publicHolidaysList.Add(Convert.ToDateTime("25.12.2015"));

            foreach (var holiday in publicHolidaysList)
            {
                if (date.Equals(holiday))
                {
                    isHoliday = true;
                    break;
                }
            }
            return isHoliday;
        }
开发者ID:AsiaBecheva,项目名称:CSharp-Part-2,代码行数:29,代码来源:WorkDays.cs

示例7: ToDateRemovesAllTimePortion

 public void ToDateRemovesAllTimePortion()
 {
   Date d1 = new DateTime(2001, 2, 3, 4, 5, 6, 7).AddTicks(8).ToDate();
   Date d2 = new Date(2001, 2, 3);
   Assert.AreEqual(d1, d2);
   Assert.IsTrue(d1.Equals(d2));
 }
开发者ID:NaveinKumar,项目名称:csharp-date,代码行数:7,代码来源:DateTests.cs

示例8: Order

 public Order(int id, string customerid, int employeeid, DateTime orderdate, DateTime requireddate, 
     DateTime shippeddate, int shipvia, double freight, string shipname, string shipaddress, string shipcity, 
     string shiparegion, string shippostalcode, string shipcountry, List<OrderDetails> details)
 {
     ID = id;
     CustomerID = customerid;
     EmployeeID = employeeid;
     OrderDate = orderdate;
     RequiredDate = requireddate;
     ShippedDate = shippeddate;
     ShipVia = shipvia;
     Freight = freight;
     ShipName = shipname;
     ShipAddress = shipaddress;
     ShipCity = shipcity;
     ShipRegion = shiparegion;
     ShipPostalCode = shippostalcode;
     ShipCountry = shipcountry;
     Details = details;
     if (orderdate.Equals(DateTime.MinValue))
         Status = OrderStatus.NEW;
     else if (ShippedDate.Equals(DateTime.MinValue))
         Status = OrderStatus.NOTSHIPPED;
     else
         Status = OrderStatus.SHIPPED;
 }
开发者ID:PozdeyevArtyom,项目名称:megarepository,代码行数:26,代码来源:Order.cs

示例9: RepairDate

        DateTime? RepairDate(DateTime? datetime)
        {
            if (datetime.HasValue && datetime.Equals(DateTime.MinValue))
                return null;

            return datetime;
        }
开发者ID:CKrowiorsch,项目名称:mediaaccount-client,代码行数:7,代码来源:ArticleListDeserializer.cs

示例10: ElectionEvent

 protected ElectionEvent(DateTime date, string name)
 {
     Contract.Requires(!date.Equals(null));
     Contract.Requires(!string.IsNullOrEmpty(name));
     _date = date;
     _name = name;
 }
开发者ID:hyllekilde,项目名称:PX3-BDSA-E2011,代码行数:7,代码来源:ElectionEvent.cs

示例11: SerieData

 private string SerieData()
 {
     string data = "";
     var transactions = (from trs in db.Transactions
                         group trs by new { Year = trs.Date.Year, Month = trs.Date.Month, Day = trs.Date.Day } into g
                         orderby g.Key.Year, g.Key.Month, g.Key.Day
                         select new { Year = g.Key.Year, Month = g.Key.Month, Day = g.Key.Day, Value = g.Max(i=>i.Rest) })
             .ToList();
     var value = transactions.First().Value;
     DateTime date = new DateTime(transactions.First().Year, transactions.First().Month, transactions.First().Day).Date;
     foreach (var transaction in transactions)
     {
         DateTime transactionDate = new DateTime(transaction.Year, transaction.Month, transaction.Day).Date;
         while (!transactionDate.Equals(date))
         {
             data += "[Date.UTC("
             + date.Year.ToString() + ","
             + (date.Month - 1).ToString() + ","
             + date.Day.ToString() + "),"
             + value.ToString().Replace(',', '.') + "],"
             ;
             date = date.AddDays(1);
         }
         value = transaction.Value;
         date = transactionDate;
         data += "[Date.UTC("
         + transaction.Year.ToString() + ","
         + (transaction.Month - 1).ToString() + ","
         + transaction.Day.ToString() + "),"
         + transaction.Value.ToString().Replace(',', '.') + "],"
         ;
     }
     return "[" + data.Remove(data.Length - 1) + "]";
 }
开发者ID:muzdima1995,项目名称:HTMLmaker,代码行数:34,代码来源:HighchartCashTime.cs

示例12: DateInBetween

        public static bool DateInBetween(DateTime targetDate, DateTime start, DateTime end)
        {
            try
            {
                if (targetDate != null && targetDate != default(DateTime))
                {
                    if (start.Equals(default(DateTime)))
                    {
                        return true;
                    }
                    if (start.CompareTo(targetDate) < 0)
                    {
                        if (end.Equals(default(DateTime)))
                            return true;
                        else if (end != default(DateTime) && end.CompareTo(targetDate) > 0)
                            return true;
                        else
                            return false;

                    }

                }
            }
            catch (Exception  ex)
            {

                Utility.WriteLogError("Exception Occurred in verification of Dates" + ex.ToString());
            }
            return false;
        }
开发者ID:sriharshakolluru,项目名称:Dinesh-Project,代码行数:30,代码来源:Utility.cs

示例13: CalculateWorkDays

    static int CalculateWorkDays(DateTime today, DateTime date)
    {
        bool isHoliday = false;
        int numberOfWorkDays = 0;

        while (today.CompareTo(date) != 1)
        {
            isHoliday = false;

            foreach (DateTime holiday in holidays)
            {
                if (today.Equals(holiday))
                {
                    isHoliday = true;
                    break;
                }
            }


            if (!isHoliday && today.DayOfWeek != DayOfWeek.Saturday && today.DayOfWeek != DayOfWeek.Sunday)
            {
                numberOfWorkDays++;
            }

            today = today.AddDays(1);
        }

        return numberOfWorkDays;
    }
开发者ID:jesusico83,项目名称:Telerik,代码行数:29,代码来源:NumberOfWorkDays.cs

示例14: ReturnNullIfEmpty

        public static object ReturnNullIfEmpty(DateTime value)
        {
            if (value.Equals(DateTime.MinValue))
                return null;

            return value;
        }
开发者ID:joncrump,项目名称:Jon.Crump.Common,代码行数:7,代码来源:DateTimeUtilities.cs

示例15: FormatDate

 public static string FormatDate(DateTime dateTime)
 {
     if (dateTime.Equals(DateTime.MinValue))
         return string.Empty;
     if (DateTime.Now.Subtract(dateTime).TotalDays > 365)
         return dateTime.ToString("yyyy");
     return DateTime.Now.Year == dateTime.Year ? dateTime.ToString("MM-dd") : dateTime.ToString("yyyy-MM-dd");
 }
开发者ID:modulexcite,项目名称:SQLoogle,代码行数:8,代码来源:Dates.cs


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