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


C# DateTimeOffset.AddSeconds方法代码示例

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


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

示例1: CreateScheduledToast

        /// <summary>
        /// Создание всплывающего уведомления
        /// </summary>
        /// <param name="timestamp"></param>
        /// <param name="id"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public static bool CreateScheduledToast(int timestamp, int id, string message)
        {
            ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier();
            var notifications = toastNotifier.GetScheduledToastNotifications();
            foreach (var notification in notifications)
            {
                if (notification.Id == id.ToString())
                    return false;
            }

            ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;
            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);

            XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
            toastTextElements[0].AppendChild(toastXml.CreateTextNode(AppConstants.AppMessages[AppConstants.UsedLanguage]["txtAppName"]));
            toastTextElements[1].AppendChild(toastXml.CreateTextNode(message));

            XmlElement toastElement = ((XmlElement)toastXml.SelectSingleNode("/toast"));
            toastElement.SetAttribute("launch", "note_id=" + id.ToString());

            DateTimeOffset schedule = new DateTimeOffset(1970, 1, 1, 0, 0, 0, new TimeSpan());
            schedule = schedule.AddSeconds(timestamp).ToLocalTime();

            ScheduledToastNotification scheduledToast = new ScheduledToastNotification(toastXml, schedule);
            scheduledToast.Id = id.ToString();

            ToastNotificationManager.CreateToastNotifier().AddToSchedule(scheduledToast);

            return true;
        }
开发者ID:azaitsevru,项目名称:simple-notes,代码行数:37,代码来源:ScheduledToast.cs

示例2: ReadJson

        /// <summary>Reads the JSON representation of the object.</summary>
        /// <param name="reader">The <see cref="JsonReader" /> to read from.</param>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="existingValue">The existing value of object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            // get epoch timestamp
            double timestamp;
            switch (reader.TokenType)
            {
                case JsonToken.Integer:
                case JsonToken.Float:
                    timestamp = (double)reader.Value;
                    break;

                case JsonToken.String:
                    try
                    {
                        timestamp = (double)Convert.ChangeType(reader.Value, typeof(double));
                    }
                    catch (FormatException ex)
                    {
                        throw new FormatException($"Can't parse string value '{reader.Value}' as a Unix timestamp.", ex);
                    }
                    break;

                default:
                    throw new Exception($"Can't parse '{reader.TokenType}' type as a Unix epoch timestamp, must be numeric.");
            }

            // convert to DateTime
            DateTimeOffset epoch = new DateTimeOffset(new DateTime(1970, 1, 1), TimeSpan.Zero);
            return epoch.AddSeconds(timestamp);
        }
开发者ID:Pathoschild,项目名称:SlackArchiveSearch,代码行数:35,代码来源:UnixDateTimeConverter.cs

示例3: Parse

        public static IEnumerable<Tuple<DateTimeOffset, decimal>> Parse(string data)
        {
            var lines = data.Split("\r\n".ToArray(), StringSplitOptions.RemoveEmptyEntries);

            var headers = new Dictionary<string, string>();

            int i;
            for (i = 0; i < lines.Length; i++)
            {
                int width = 1;
                var index = lines[i].IndexOf("=");
                if (index == -1)
                {
                    width = 3;
                    index = lines[i].IndexOf("%3D");
                }

                if (index == -1)
                {
                    break;
                }

                headers.Add(lines[i].Substring(0, index), lines[i].Substring(index + width));
            }

            var columns = headers["COLUMNS"]
                .Split(',')
                .Select((col, ix) => new { col, ix })
                .ToDictionary(e => e.col, e => e.ix);

            var interval = int.Parse(headers["INTERVAL"]);
            var tz = int.Parse(headers["TIMEZONE_OFFSET"]);
            var epoch = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.FromMinutes(tz));

            var reference = epoch;
            for (; i < lines.Length; i++)
            {
                var cols = lines[i].Split(',');

                var dateStr = cols[columns["DATE"]];
                var closeStr = cols[columns["CLOSE"]];

                int offset;
                if (dateStr.StartsWith("a"))
                {
                    reference = epoch.AddSeconds(int.Parse(dateStr.Substring(1)));
                    offset = 0;
                }
                else
                {
                    offset = int.Parse(dateStr);
                }

                var date = reference.AddSeconds(offset * interval);
                var close = decimal.Parse(closeStr);

                yield return Tuple.Create(date, close);
            }
        }
开发者ID:otac0n,项目名称:SharpBooks,代码行数:59,代码来源:GoogleCurrencyPriceQuoteSource.cs

示例4: AssignedDateTime

 /// <summary>
 /// A DateTimeOffset value is not tied to a particular time zone, but can originate from any of a variety of time zones. 
 /// Return assigned DateTime.
 /// </summary>
 /// <param name="ipAddress">Object of IPAddress.</param>
 /// <returns>Assigned DateTime</returns>
 public static DateTimeOffset? AssignedDateTime(this IPAddress ipAddress)
 {
     IPv4Data data = GetIPv4Data(ipAddress);
     if (data == null)
     {
         return null;
     }
     DateTimeOffset offset = new DateTimeOffset(0x7b2, 1, 1, 0, 0, 0, 0, new TimeSpan(0, 0, 0));
     return new DateTimeOffset?(offset.AddSeconds((double)data.Assigned));
 }
开发者ID:xiaoxiaocoder,项目名称:AspxCommerce2.7,代码行数:16,代码来源:IPAddressExtensions.cs

示例5: ParseRateLimit

        private static RateLimit ParseRateLimit(HttpResponseHeaders headers)
        {
            // Determine reset
            long resetInUnixTime = GetHeaderValue(headers, "x-ratelimit-reset");
            DateTimeOffset epoch = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
            DateTimeOffset reset = epoch.AddSeconds(resetInUnixTime);

            return new RateLimit
            {
                Limit = GetHeaderValue(headers, "x-ratelimit-limit"),
                Remaining = GetHeaderValue(headers, "x-ratelimit-remaining"),
                Reset = reset
            };
        }
开发者ID:jerriep,项目名称:auth0.net,代码行数:14,代码来源:ApiInfoParser.cs

示例6: QuickPulseCollectionTimeSlotManagerHandlesSecondHalfOfSecond

        public void QuickPulseCollectionTimeSlotManagerHandlesSecondHalfOfSecond()
        {
            // ARRANGE
            var manager = new QuickPulseCollectionTimeSlotManager();

            var now = new DateTimeOffset(2016, 1, 1, 0, 0, 1, TimeSpan.Zero);
            now = now.AddMilliseconds(501);

            // ACT
            DateTimeOffset slot = manager.GetNextCollectionTimeSlot(now);

            // ASSERT
            Assert.AreEqual(now.AddSeconds(1).AddMilliseconds(-1), slot);
        }
开发者ID:xornand,项目名称:ApplicationInsights-dotnet-server,代码行数:14,代码来源:QuickPulseCollectionTimeSlotManagerTests.cs

示例7: From_FromFixedDateTime_Tests

    public void From_FromFixedDateTime_Tests(int value)
    {
        var originalPointInTime = new DateTimeOffset(1976, 12, 31, 17, 0, 0, 0, TimeSpan.Zero);

        Assert.AreEqual(value.Years().From(originalPointInTime), originalPointInTime.AddYears(value));
        Assert.AreEqual(value.Months().From(originalPointInTime), originalPointInTime.AddMonths(value));
        Assert.AreEqual(value.Weeks().From(originalPointInTime), originalPointInTime.AddDays(value*DaysPerWeek));
        Assert.AreEqual(value.Days().From(originalPointInTime), originalPointInTime.AddDays(value));

        Assert.AreEqual(value.Hours().From(originalPointInTime), originalPointInTime.AddHours(value));
        Assert.AreEqual(value.Minutes().From(originalPointInTime), originalPointInTime.AddMinutes(value));
        Assert.AreEqual(value.Seconds().From(originalPointInTime), originalPointInTime.AddSeconds(value));
        Assert.AreEqual(value.Milliseconds().From(originalPointInTime), originalPointInTime.AddMilliseconds(value));
        Assert.AreEqual(value.Ticks().From(originalPointInTime), originalPointInTime.AddTicks(value));
    }
开发者ID:jin29neci,项目名称:FluentDateTime,代码行数:15,代码来源:DateTimeOffsetTests.cs

示例8: TestAddition

    public static void TestAddition()
    {
        DateTimeOffset dt = new DateTimeOffset(new DateTime(1986, 8, 15, 10, 20, 5, 70));
        Assert.Equal(17, dt.AddDays(2).Day);
        Assert.Equal(13, dt.AddDays(-2).Day);

        Assert.Equal(10, dt.AddMonths(2).Month);
        Assert.Equal(6, dt.AddMonths(-2).Month);

        Assert.Equal(1996, dt.AddYears(10).Year);
        Assert.Equal(1976, dt.AddYears(-10).Year);

        Assert.Equal(13, dt.AddHours(3).Hour);
        Assert.Equal(7, dt.AddHours(-3).Hour);

        Assert.Equal(25, dt.AddMinutes(5).Minute);
        Assert.Equal(15, dt.AddMinutes(-5).Minute);

        Assert.Equal(35, dt.AddSeconds(30).Second);
        Assert.Equal(2, dt.AddSeconds(-3).Second);

        Assert.Equal(80, dt.AddMilliseconds(10).Millisecond);
        Assert.Equal(60, dt.AddMilliseconds(-10).Millisecond);
    }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:24,代码来源:DateTimeOffset.cs

示例9: ReadJson

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            long ticks;

            if (!long.TryParse(reader.Value.ToString(), out ticks))
            {
                throw new Exception(
                    String.Format("Unexpected token parsing date. Expected Integer, got {0}.",
                    reader.TokenType));
            }

            var date = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
            date = date.AddSeconds(ticks);

            return date;
        }
开发者ID:sheepsteak,项目名称:EchoesJS,代码行数:16,代码来源:CTimeToDateTimeOffsetConverter.cs

示例10: RoundsToNearestSecond

        public void RoundsToNearestSecond()
        {
            var now = new DateTimeOffset(2015, 03, 04, 20, 07, 21, TimeSpan.Zero);

            var testDto1 = now.AddMilliseconds(450);
            var actualDto1 = testDto1.RoundToNearestSecond();

            Assert.AreEqual(now, actualDto1);
            TestHelper.AssertSerialiseEqual(now, actualDto1);

            var expectedDto2 = now.AddSeconds(1);
            var testDto2 = now.AddMilliseconds(550);
            var actualDto2 = testDto2.RoundToNearestSecond();

            Assert.AreEqual(expectedDto2, actualDto2);
            TestHelper.AssertSerialiseEqual(expectedDto2, actualDto2);
        }
开发者ID:roberdjp,项目名称:lastfm,代码行数:17,代码来源:TestHelperTests.cs

示例11: GetTestScrobbles

        private List<Scrobble> GetTestScrobbles()
        {
            var counter = 0;
            var now = new DateTimeOffset(2012, 02, 29, 15, 40, 03, TimeSpan.Zero);
            Func<DateTimeOffset> getTimePlayed = () => now.AddSeconds(-360 * counter++);

            var testScrobbles = new List<Scrobble>
            {
                new Scrobble("65daysofstatic", "The Fall of Math", "Hole", getTimePlayed())
                {
                    ChosenByUser = true
                },
                new Scrobble("やくしまるえつこ", "X次元へようこそ", "X次元へようこそ", getTimePlayed())
                {
                    AlbumArtist = "やくしまるえつこ",
                    ChosenByUser = false
                },
                new Scrobble("Björk", "Hyperballad", "Post", getTimePlayed())
                {
                    AlbumArtist = "Björk",
                    ChosenByUser = false
                },
                new Scrobble("Broken Social Scene", "Sentimental X's", "Forgiveness Rock Record", getTimePlayed())
                {
                    AlbumArtist = "Broken Social Scene",
                    ChosenByUser = false
                },
                new Scrobble("Rubies", "Stand in a Line", "Teppan-Yaki (A Collection of Remixes)", getTimePlayed())
                {
                    AlbumArtist = "Schinichi Osawa",
                    ChosenByUser = false
                }
            };

            return testScrobbles;
        }
开发者ID:roberdjp,项目名称:lastfm,代码行数:36,代码来源:ScrobblerTestsBase.cs

示例12: Round

		public static DateTimeOffset Round(this DateTimeOffset dateTime, RoundTo rt)
		{
			DateTimeOffset rounded;

		    switch (rt)
			{
				case RoundTo.Second:
					{
                        rounded = new DateTimeOffset(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second,dateTime.Offset);
						if (dateTime.Millisecond >= 500)
						{
							rounded = rounded.AddSeconds(1);
						}
						break;
					}
				case RoundTo.Minute:
					{
                        rounded = new DateTimeOffset(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, 0,dateTime.Offset);
						if (dateTime.Second >= 30)
						{
							rounded = rounded.AddMinutes(1);
						}
						break;
					}
				case RoundTo.Hour:
					{
                        rounded = new DateTimeOffset(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, 0, 0,dateTime.Offset);
						if (dateTime.Minute >= 30)
						{
							rounded = rounded.AddHours(1);
						}
						break;
					}
				case RoundTo.Day:
					{
                        rounded = new DateTimeOffset(dateTime.Year, dateTime.Month, dateTime.Day, 0, 0, 0,dateTime.Offset);
						if (dateTime.Hour >= 12)
						{
							rounded = rounded.AddDays(1);
						}
						break;
					}
				default:
					{
                        throw new ArgumentOutOfRangeException("rt");
					}
			}

			return rounded;
		}
开发者ID:jin29neci,项目名称:FluentDateTime,代码行数:50,代码来源:DateTimeExtensions.cs

示例13: GetTimeAfter

        /// <summary>
        /// Gets the next fire time after the given time.
        /// </summary>
        /// <param name="afterTimeUtc">The UTC time to start searching from.</param>
        /// <returns></returns>
        public virtual DateTimeOffset? GetTimeAfter(DateTimeOffset afterTimeUtc)
        {
            // move ahead one second, since we're computing the time *after* the
            // given time
            afterTimeUtc = afterTimeUtc.AddSeconds(1);

            // CronTrigger does not deal with milliseconds
            DateTimeOffset d = CreateDateTimeWithoutMillis(afterTimeUtc);

            // change to specified time zone
            d = TimeZoneUtil.ConvertTime(d, TimeZone);

            bool gotOne = false;
            // loop until we've computed the next time, or we've past the endTime
            while (!gotOne)
            {
                ISortedSet<int> st;
                int t;
                int sec = d.Second;

                // get second.................................................
                st = seconds.TailSet(sec);
                if (st != null && st.Count != 0)
                {
                    sec = st.First();
                }
                else
                {
                    sec = seconds.First();
                    d = d.AddMinutes(1);
                }
                d = new DateTimeOffset(d.Year, d.Month, d.Day, d.Hour, d.Minute, sec, d.Millisecond, d.Offset);

                int min = d.Minute;
                int hr = d.Hour;
                t = -1;

                // get minute.................................................
                st = minutes.TailSet(min);
                if (st != null && st.Count != 0)
                {
                    t = min;
                    min = st.First();
                }
                else
                {
                    min = minutes.First();
                    hr++;
                }
                if (min != t)
                {
                    d = new DateTimeOffset(d.Year, d.Month, d.Day, d.Hour, min, 0, d.Millisecond, d.Offset);
                    d = SetCalendarHour(d, hr);
                    continue;
                }
                d = new DateTimeOffset(d.Year, d.Month, d.Day, d.Hour, min, d.Second, d.Millisecond, d.Offset);

                hr = d.Hour;
                int day = d.Day;
                t = -1;

                // get hour...................................................
                st = hours.TailSet(hr);
                if (st != null && st.Count != 0)
                {
                    t = hr;
                    hr = st.First();
                }
                else
                {
                    hr = hours.First();
                    day++;
                }
                if (hr != t)
                {
                    int daysInMonth = DateTime.DaysInMonth(d.Year, d.Month);
                    if (day > daysInMonth)
                    {
                        d = new DateTimeOffset(d.Year, d.Month, daysInMonth, d.Hour, 0, 0, d.Millisecond, d.Offset).AddDays(day - daysInMonth);
                    }
                    else
                    {
                        d = new DateTimeOffset(d.Year, d.Month, day, d.Hour, 0, 0, d.Millisecond, d.Offset);
                    }
                    d = SetCalendarHour(d, hr);
                    continue;
                }
                d = new DateTimeOffset(d.Year, d.Month, d.Day, hr, d.Minute, d.Second, d.Millisecond, d.Offset);

                day = d.Day;
                int mon = d.Month;
                t = -1;
                int tmon = mon;

                // get day...................................................
//.........这里部分代码省略.........
开发者ID:edwardt,项目名称:quartznet,代码行数:101,代码来源:CronExpression.cs

示例14: GetNextInvalidTimeAfter

        /// <summary>
        /// Returns the next date/time <i>after</i> the given date/time which does
        /// <i>not</i> satisfy the expression.
        /// </summary>
        /// <param name="date">the date/time at which to begin the search for the next invalid date/time</param>
        /// <returns>the next valid date/time</returns>
        public virtual DateTimeOffset? GetNextInvalidTimeAfter(DateTimeOffset date)
        {
            long difference = 1000;

            //move back to the nearest second so differences will be accurate
            DateTimeOffset lastDate =
                new DateTimeOffset(date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second, date.Offset).AddSeconds(-1);

            //TODO: IMPROVE THIS! The following is a BAD solution to this problem. Performance will be very bad here, depending on the cron expression. It is, however A solution.

            //keep getting the next included time until it's farther than one second
            // apart. At that point, lastDate is the last valid fire time. We return
            // the second immediately following it.
            while (difference == 1000)
            {
                DateTimeOffset? newDate = GetTimeAfter(lastDate);

                if (newDate == null)
                {
                    break;
                }

                difference = (long) (newDate.Value - lastDate).TotalMilliseconds;

                if (difference == 1000)
                {
                    lastDate = newDate.Value;
                }
            }

            return lastDate.AddSeconds(1);
        }
开发者ID:edwardt,项目名称:quartznet,代码行数:38,代码来源:CronExpression.cs

示例15: EpochSecondsToDateTime

 /// <summary>
 /// Datetime from an int representing a unix epoch time
 /// </summary>
 /// <param name="secondsSinceEpoch"></param>
 /// <returns></returns>
 public static DateTimeOffset EpochSecondsToDateTime(this int secondsSinceEpoch)
 {
     var date = new DateTimeOffset(1970, 1, 1,0,0,0,TimeSpan.Zero);
     return date.AddSeconds(secondsSinceEpoch);
 }
开发者ID:orianbsilva,项目名称:kafka4net,代码行数:10,代码来源:DateTimeExtensions.cs


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