本文整理汇总了C#中DateTimeOffset.AddMinutes方法的典型用法代码示例。如果您正苦于以下问题:C# DateTimeOffset.AddMinutes方法的具体用法?C# DateTimeOffset.AddMinutes怎么用?C# DateTimeOffset.AddMinutes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTimeOffset
的用法示例。
在下文中一共展示了DateTimeOffset.AddMinutes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitCustomers
private static void InitCustomers()
{
DateTimeOffset dto = new DateTimeOffset(2015, 1, 1, 1, 2, 3, 4, TimeSpan.Zero);
_customers = Enumerable.Range(1, 5).Select(e =>
new DCustomer
{
Id = e,
DateTime = dto.AddYears(e).DateTime,
Offset = e % 2 == 0 ? dto.AddMonths(e) : dto.AddDays(e).AddMilliseconds(10),
Date = e % 2 == 0 ? dto.AddDays(e).Date : dto.AddDays(-e).Date,
TimeOfDay = e % 3 == 0 ? dto.AddHours(e).TimeOfDay : dto.AddHours(-e).AddMilliseconds(10).TimeOfDay,
NullableDateTime = e % 2 == 0 ? (DateTime?)null : dto.AddYears(e).DateTime,
NullableOffset = e % 3 == 0 ? (DateTimeOffset?)null : dto.AddMonths(e),
NullableDate = e % 2 == 0 ? (Date?)null : dto.AddDays(e).Date,
NullableTimeOfDay = e % 3 == 0 ? (TimeOfDay?)null : dto.AddHours(e).TimeOfDay,
DateTimes = new [] { dto.AddYears(e).DateTime, dto.AddMonths(e).DateTime },
Offsets = new [] { dto.AddMonths(e), dto.AddDays(e) },
Dates = new [] { (Date)dto.AddYears(e).Date, (Date)dto.AddMonths(e).Date },
TimeOfDays = new [] { (TimeOfDay)dto.AddHours(e).TimeOfDay, (TimeOfDay)dto.AddMinutes(e).TimeOfDay },
NullableDateTimes = new [] { dto.AddYears(e).DateTime, (DateTime?)null, dto.AddMonths(e).DateTime },
NullableOffsets = new [] { dto.AddMonths(e), (DateTimeOffset?)null, dto.AddDays(e) },
NullableDates = new [] { (Date)dto.AddYears(e).Date, (Date?)null, (Date)dto.AddMonths(e).Date },
NullableTimeOfDays = new [] { (TimeOfDay)dto.AddHours(e).TimeOfDay, (TimeOfDay?)null, (TimeOfDay)dto.AddMinutes(e).TimeOfDay },
}).ToList();
}
示例2: TurnOffDevice
public static void TurnOffDevice(string deviceId, DateTimeOffset departureTime)
{
SNMPDemoContext db = new SNMPDemoContext();
//Device dev = db.Devices.Find(Int32.Parse(deviceId));
string jobIdentity = "PreHeaterOffJob" + deviceId;
string triggerIdentity = "PreHeaterOffTrigger" + deviceId;
//DateTimeOffset turnOffTimer = departureTime;
//turnOffTimer = turnOffTimer.AddMinutes(-5);
departureTime = departureTime.AddMinutes(-5);
// Build a job
IJobDetail job = JobBuilder.Create<SetPreHeaterOffJob>()
.WithIdentity(jobIdentity, "group1")
//.UsingJobData("ip", dev.IpAddress)
//.UsingJobData("communityString", dev.CommunityString)
.UsingJobData("deviceId", deviceId)
.Build();
// Build a trigger
ISimpleTrigger trigger = (ISimpleTrigger)TriggerBuilder.Create()
.WithIdentity(triggerIdentity, "group1")
.StartAt(departureTime)
.Build();
// Schedule a job with the trigger
MvcApplication.Scheduler.ScheduleJob(job, trigger);
}
示例3: RoundToNearest
public static DateTimeOffset RoundToNearest(this DateTimeOffset time, int minutes)
{
var mins = time.Minute;
var intervals = (int)((mins + (minutes / 2)) / minutes);
mins = (intervals * minutes);
var result = new DateTimeOffset(time.Year, time.Month, time.Day, time.Hour, 0, 0, time.Offset);
return result.AddMinutes(mins);
}
示例4: Main
static void Main(string[] args)
{
//var offset = DateTimeOffset.Now;
//Debug.WriteLine(offset);
//Debug.WriteLine(DateTimeOffset.UtcNow);
//String s = "10/1/2014 6:17 PM";
//DateTime dt = DateTime.ParseExact(s, "MM/dd/yyyy h:mm tt", CultureInfo.InvariantCulture);
//DateTimeOffset dto = new DateTimeOffset(dt);
DateTimeOffset dto1 = new DateTimeOffset();
dto1 = DateTimeOffset.Now;
dto1 = dto1.AddHours(2);
dto1 = dto1.AddMinutes(30);
Debug.WriteLine(DateTimeOffset.Now);
Debug.WriteLine(dto1);
TimeSpan diff = dto1.Subtract(DateTimeOffset.Now);
Debug.WriteLine(diff);
Debug.WriteLine(diff.TotalHours);
Debug.WriteLine(diff.TotalSeconds);
var diffsec = (DateTimeOffset.Now - dto1).TotalSeconds;
Debug.WriteLine(diffsec);
//dtoff.Value.ToLocalTime().ToString("dddd, MMM dd yyyy HH:mm", new CultureInfo("en-US"));
//Debug.WriteLine(dto1);
//Debug.WriteLine(dto2);
//Debug.WriteLine(DateTimeOffset.Now);
//Debug.WriteLine(dto1 - DateTimeOffset.Now);
//Debug.WriteLine(DateTimeOffset.Now - dto1);
//Debug.WriteLine(dto1.CompareTo(DateTimeOffset.Now));
//Debug.WriteLine(DateTimeOffset.Now.CompareTo(dto1));
//Debug.WriteLine(" ");
//Debug.WriteLine(dto1.Hour);
double temp = -26;
double res = 0;
for (int i = 0; i < 40; i++)
{
temp++;
res = 0.5 - (temp * 0.1);
Debug.WriteLine("Temp: " + temp + " Result: " + res);
}
//Debug.WriteLine(s);
//Debug.WriteLine(dt.ToString());
//Debug.WriteLine(dt.ToUniversalTime().ToString());
//Debug.WriteLine(dto.ToString());
}
示例5: ScheduleNextTime
public DateTimeOffset ScheduleNextTime(DateTimeOffset currentTime, JobExecutionRecord lastExecution)
{
var hour = new DateTimeOffset(currentTime.Year, currentTime.Month, currentTime.Day, currentTime.Hour, 0, 0,
currentTime.Offset);
while (hour < currentTime)
{
hour = hour.AddMinutes(10);
}
return hour;
}
示例6: GetSendDate
private static DateTimeOffset? GetSendDate(DateTimeOffset now, ApplicationPushNotificationSetting appSettings, SubscriberNotificationSetting userNoteSettings)
{
DateTimeOffset? send = null;
if (userNoteSettings.IsEnabled)
{
var addMinutes = appSettings.AntiNoiseSettings.IsConsolidationEnabled
? appSettings.AntiNoiseSettings.InitialConsolidationDelayMinutes
: 0;
send = now.AddMinutes(addMinutes);
}
return send;
}
示例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));
}
示例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);
}
示例9: ToRelativeTimeTest
public void ToRelativeTimeTest()
{
var date = new DateTimeOffset(2015, 8, 7, 13, 26, 30, TimeSpan.Zero);
var now = DateTimeOffset.Now;
Assert.AreEqual("now", now.ToRelativeTimeString());
Assert.AreEqual("now", now.ToRelativeTimeString(now));
Assert.AreEqual("1 second ago", date.AddSeconds(-1).ToRelativeTimeString(date));
Assert.AreEqual("10 seconds ago", date.AddSeconds(-10).ToRelativeTimeString(date));
Assert.AreEqual("1 minute ago", date.AddSeconds(-90).ToRelativeTimeString(date));
Assert.AreEqual("1 minute ago", date.AddSeconds(-100).ToRelativeTimeString(date));
Assert.AreEqual("2 minutes ago", date.AddSeconds(-120).ToRelativeTimeString(date));
Assert.AreEqual("7 minutes ago", date.AddMinutes(-7).ToRelativeTimeString(date));
Assert.AreEqual("59 minutes ago", date.AddMinutes(-59).ToRelativeTimeString(date));
Assert.AreEqual("1 hour ago", date.AddMinutes(-60).ToRelativeTimeString(date));
Assert.AreEqual("1 hour ago", date.AddHours(-1).ToRelativeTimeString(date));
Assert.AreEqual("9 hours ago", date.AddHours(-9).ToRelativeTimeString(date));
Assert.AreEqual("1 day ago", date.AddHours(-24).ToRelativeTimeString(date));
Assert.AreEqual("1 day ago", date.AddHours(-30).ToRelativeTimeString(date));
Assert.AreEqual("2 days ago", date.AddHours(-48).ToRelativeTimeString(date));
Assert.AreEqual("1 day ago", date.AddDays(-1).ToRelativeTimeString(date));
Assert.AreEqual("12 days ago", date.AddDays(-12).ToRelativeTimeString(date));
Assert.AreEqual("29 days ago", date.AddDays(-29).ToRelativeTimeString(date));
Assert.AreEqual("1 month ago", date.AddDays(-30).ToRelativeTimeString(date));
Assert.AreEqual("1 month ago", date.AddMonths(-1).ToRelativeTimeString(date));
Assert.AreEqual("3 months ago", date.AddMonths(-3).ToRelativeTimeString(date));
Assert.AreEqual("11 months ago", date.AddMonths(-11).ToRelativeTimeString(date));
Assert.AreEqual("1 year ago", date.AddMonths(-12).ToRelativeTimeString(date));
Assert.AreEqual("1 year ago", date.AddYears(-1).ToRelativeTimeString(date));
Assert.AreEqual("3 years ago", date.AddYears(-3).ToRelativeTimeString(date));
Assert.AreEqual("1 second from now", date.AddSeconds(1).ToRelativeTimeString(date));
Assert.AreEqual("10 seconds from now", date.AddSeconds(10).ToRelativeTimeString(date));
Assert.AreEqual("1 minute from now", date.AddSeconds(90).ToRelativeTimeString(date));
Assert.AreEqual("1 minute from now", date.AddSeconds(100).ToRelativeTimeString(date));
Assert.AreEqual("2 minutes from now", date.AddSeconds(120).ToRelativeTimeString(date));
Assert.AreEqual("7 minutes from now", date.AddMinutes(7).ToRelativeTimeString(date));
Assert.AreEqual("59 minutes from now", date.AddMinutes(59).ToRelativeTimeString(date));
Assert.AreEqual("1 hour from now", date.AddMinutes(60).ToRelativeTimeString(date));
Assert.AreEqual("1 hour from now", date.AddHours(1).ToRelativeTimeString(date));
Assert.AreEqual("9 hours from now", date.AddHours(9).ToRelativeTimeString(date));
Assert.AreEqual("1 day from now", date.AddDays(1).ToRelativeTimeString(date));
Assert.AreEqual("1 day from now", date.AddHours(24).ToRelativeTimeString(date));
Assert.AreEqual("12 days from now", date.AddDays(12).ToRelativeTimeString(date));
Assert.AreEqual("29 days from now", date.AddDays(29).ToRelativeTimeString(date));
Assert.AreEqual("1 month from now", date.AddDays(30).ToRelativeTimeString(date));
Assert.AreEqual("1 month from now", date.AddMonths(1).ToRelativeTimeString(date));
Assert.AreEqual("3 months from now", date.AddMonths(3).ToRelativeTimeString(date));
Assert.AreEqual("11 months from now", date.AddMonths(11).ToRelativeTimeString(date));
Assert.AreEqual("1 year from now", date.AddMonths(12).ToRelativeTimeString(date));
Assert.AreEqual("1 year from now", date.AddYears(1).ToRelativeTimeString(date));
Assert.AreEqual("3 years from now", date.AddYears(3).ToRelativeTimeString(date));
}
示例10: AppendTileWithBlockTextAndLines
/// <summary>
/// Appends a wide tile with a big block of text. Used to display up-coming buses.
/// </summary>
public void AppendTileWithBlockTextAndLines(DateTimeOffset scheduledTime, string blockText, string subBlockText, string text1 = null, string text2 = null, string text3 = null, string text4 = null)
{
//<tile>
// <visual>
// <binding template="TileWideBlockAndText01">
// <text id="1">Text Field 1</text>
// <text id="2">Text Field 2</text>
// <text id="3">Text Field 3</text>
// <text id="4">Text Field 4</text>
// <text id="5">T5</text>
// <text id="6">Text Field 6</text>
// </binding>
// </visual>
//</tile>
var document = new XmlDocument();
var rootElement = document.CreateElement("tile");
document.AppendChild(rootElement);
XmlElement visualElement = document.CreateElement("visual");
rootElement.AppendChild(visualElement);
XmlElement wideBindingElement = document.CreateElement("binding");
wideBindingElement.SetAttribute("template", "TileWideBlockAndText01");
visualElement.AppendChild(wideBindingElement);
string[] wideTexts = new string[]
{
text1,
text2,
text3,
text4,
blockText,
subBlockText,
};
for (int i = 0; i < wideTexts.Length; i++)
{
string text = wideTexts[i];
if (!string.IsNullOrEmpty(text))
{
XmlElement textElement = document.CreateElement("text");
textElement.SetAttribute("id", (i + 1).ToString());
textElement.InnerText = text;
wideBindingElement.AppendChild(textElement);
}
}
// Unfortunately, there is only one small tile template that supports block text.
//<tile>
// <visual>
// <binding template="TileSquareBlock">
// <text id="1">Text Field 1</text>
// <text id="2">Text Field 2</text>
// </binding>
// </visual>
//</tile>
XmlElement smallBindingElement = document.CreateElement("binding");
smallBindingElement.SetAttribute("template", "TileSquareBlock");
visualElement.AppendChild(smallBindingElement);
XmlElement smallBlockTextElement = document.CreateElement("text");
smallBlockTextElement.SetAttribute("id", "1");
smallBlockTextElement.InnerText = blockText;
smallBindingElement.AppendChild(smallBlockTextElement);
XmlElement smallSubTextElement = document.CreateElement("text");
smallSubTextElement.SetAttribute("id", "2");
smallSubTextElement.InnerText = text1;
smallBindingElement.AppendChild(smallSubTextElement);
if ((scheduledTime - DateTime.Now).TotalMinutes < 1)
{
var notification = new TileNotification(document);
notification.ExpirationTime = scheduledTime.AddMinutes(1);
notification.Tag = (text1 + text2 + text3 + scheduledTime.ToString("hh:mm")).GetHashCode().ToString("X");
this.tileUpdater.Update(notification);
}
else
{
var notification = new ScheduledTileNotification(document, scheduledTime);
notification.ExpirationTime = scheduledTime.AddMinutes(1);
notification.Tag = (text1 + text2 + text3 + scheduledTime.ToString("hh:mm")).GetHashCode().ToString("X");
this.tileUpdater.AddToSchedule(notification);
}
}
示例11: ProcessAsync_UsesExpiresOn_ToExpireCacheEntry
public async Task ProcessAsync_UsesExpiresOn_ToExpireCacheEntry()
{
// Arrange - 1
var currentTime = new DateTimeOffset(2010, 1, 1, 0, 0, 0, TimeSpan.Zero);
var id = "unique-id";
var childContent1 = "original-child-content";
var clock = new Mock<ISystemClock>();
clock.SetupGet(p => p.UtcNow)
.Returns(() => currentTime);
var cache = new MemoryCache(new MemoryCacheOptions { Clock = clock.Object });
var tagHelperContext1 = GetTagHelperContext(id, childContent1);
var tagHelperOutput1 = new TagHelperOutput("cache", new TagHelperAttributeList { { "attr", "value" } });
tagHelperOutput1.PreContent.SetContent("<cache>");
tagHelperOutput1.PostContent.SetContent("</cache>");
var cacheTagHelper1 = new CacheTagHelper(cache)
{
ViewContext = GetViewContext(),
ExpiresOn = currentTime.AddMinutes(5)
};
// Act - 1
await cacheTagHelper1.ProcessAsync(tagHelperContext1, tagHelperOutput1);
// Assert - 1
Assert.Empty(tagHelperOutput1.PreContent.GetContent());
Assert.Empty(tagHelperOutput1.PostContent.GetContent());
Assert.True(tagHelperOutput1.IsContentModified);
Assert.Equal(childContent1, tagHelperOutput1.Content.GetContent());
// Arrange - 2
currentTime = currentTime.AddMinutes(5).AddSeconds(2);
var childContent2 = "different-content";
var tagHelperContext2 = GetTagHelperContext(id, childContent2);
var tagHelperOutput2 = new TagHelperOutput("cache", new TagHelperAttributeList { { "attr", "value" } });
tagHelperOutput2.PreContent.SetContent("<cache>");
tagHelperOutput2.PostContent.SetContent("</cache>");
var cacheTagHelper2 = new CacheTagHelper(cache)
{
ViewContext = GetViewContext(),
ExpiresOn = currentTime.AddMinutes(5)
};
// Act - 2
await cacheTagHelper2.ProcessAsync(tagHelperContext2, tagHelperOutput2);
// Assert - 2
Assert.Empty(tagHelperOutput2.PreContent.GetContent());
Assert.Empty(tagHelperOutput2.PostContent.GetContent());
Assert.True(tagHelperOutput2.IsContentModified);
Assert.Equal(childContent2, tagHelperOutput2.Content.GetContent());
}
示例12: AddMinutes
public static void AddMinutes(DateTimeOffset dateTimeOffset, double minutes, DateTimeOffset expected)
{
Assert.Equal(expected, dateTimeOffset.AddMinutes(minutes));
}
示例13: RenderArrivalTime
private static string RenderArrivalTime(DateTimeOffset currentTime, int minutesFromNow)
{
if (minutesFromNow > 30)
{
return currentTime.AddMinutes(minutesFromNow).ToString("h:mm tt");
}
if (minutesFromNow == 1)
{
return $"{minutesFromNow} minute";
}
return $"{minutesFromNow} minutes";
}
示例14: buyMag_Click
private async void buyMag_Click(object sender, RoutedEventArgs e)
{
if (licenseInformation == null) return;
if (!licenseInformation.ProductLicenses[product_id].IsActive)
{
try
{
// The customer doesn't own this feature, so
// show the purchase dialog.
var receipt = await CurrentAppSimulator.RequestProductPurchaseAsync(product_id, true);
if (!licenseInformation.ProductLicenses[product_id].IsActive || receipt == "") return;
await DownloadManager.StoreReceiptAsync(product_id, receipt);
// the in-app purchase was successful
// TEST ONLY
// =================================================
var f = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(@"Assets\test\receipt.pmd");
var xml = new XmlDocument();
xml = await XmlDocument.LoadFromFileAsync(f);
var item = xml.GetElementsByTagName("ProductReceipt")[0] as XmlElement;
item.SetAttribute("ProductId", product_id);
var date = new DateTimeOffset(DateTime.Now);
date = date.AddMinutes(3);
var str = date.ToString("u");
str = str.Replace(" ", "T");
item.SetAttribute("ExpirationDate", str);
receipt = xml.GetXml();
if (DownloadManager.ReceiptExpired(receipt)) return;
// =================================================
buyMag.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
if (Bought != null)
{
Bought(this, DownloadManager.GetUrl(product_id, receipt, relativePath));
this.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
}
else
{
var messageDialog = new MessageDialog("Purchase successfull");
var task = messageDialog.ShowAsync().AsTask();
}
}
catch (Exception)
{
// The in-app purchase was not completed because
// an error occurred.
var messageDialog = new MessageDialog("Unexpected error");
var task = messageDialog.ShowAsync().AsTask();
}
}
else
{
var messageDialog = new MessageDialog("You already purchased this app");
var task = messageDialog.ShowAsync().AsTask();
}
}
示例15: Subtracting
public void Subtracting()
{
var now = new DateTimeOffset(2013, 8, 13, 13, 0, 0, TimeSpan.FromHours(12));
var tick = new TimeSpan(1);
var time = new TimeRange(now, now.AddHours(1));
var before = new TimeRange(now - TimeSpan.FromHours(1), time.StartsOn);
var after = new TimeRange(time.EndsOn, TimeSpan.FromHours(1));
var mid = new TimeRange(now.AddMinutes(15), TimeSpan.FromMinutes(30));
// No intersection
Assert.AreEqual(1, time.Subtract(before).Count());
Assert.AreEqual(time, time.Subtract(before).First());
Assert.AreEqual(1, time.Subtract(after).Count());
Assert.AreEqual(time, time.Subtract(after).First());
// Identity
Assert.AreEqual(0, time.Subtract(time).Count());
// Subsumes
Assert.AreEqual(0, time.Subtract(new TimeRange(before.StartsOn, after.EndsOn)).Count());
// Middle
Assert.AreEqual(2, time.Subtract(mid).Count());
Assert.IsTrue(time.Subtract(mid).Any(t => t.StartsOn == now && t.Duration == TimeSpan.FromMinutes(15)));
Assert.IsTrue(time.Subtract(mid).Any(t => t.StartsOn == now.AddMinutes(45) && t.Duration == TimeSpan.FromMinutes(15)));
}