當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。