DateTime.addDate()不起作用! [英] DateTime.addDate() not working!

查看:220
本文介绍了DateTime.addDate()不起作用!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,如果我在"调试模式"中运行应用程序,我正在使用后台代理处理WP8应用程序。它工作正常,但当我尝试使用"Relase模式"时在Visual Studio中它给我一个关于此操作的OutOfRangeException:

 periodicTask.ExpirationTime = DateTime.Now.AddDays(14); 

我发现在"调试模式"下运行时DateTime.Now.AddDays(14)返回正确的DateTime,但如果我运行:

 MessageBox.Show(DateTime.Now.AddDays(14).ToString() ); 

in"Relase mode"它返回DateTime.Now值并且不会添加14天而我猜测periodickTask.ExpirationTime不接受当前DateTime作为值。


不知道它是否相关但是我我在8.1预览的设备上测试。


任何提示?


感谢您的帮助

解决方案

ExpirationTime必须是当前日期的14天或更短时间。向DateTime.Now添加14天可能会使ExpirationTime超过14天。所以尝试DateTime.Today而不是DateTime.Now

 periodicTask.ExpirationTime = DateTime.Today.AddDays(14); 




http://msdn.microsoft.com/en-US/library/windowsphone/develop/microsoft.phone.scheduler.periodictask.expirationtime(v = vs.105).aspx


Hi guys, I'm working on a WP8 app with a background agent, if I run the app in "debug mode" it works fine but when I try to use "Relase mode" in Visual Studio it give me an OutOfRangeException on this operation:

periodicTask.ExpirationTime = DateTime.Now.AddDays(14);

I found out that when running in "debug mode" DateTime.Now.AddDays(14) return the right DateTime, but if I run:

MessageBox.Show(DateTime.Now.AddDays(14).ToString());

in "Relase mode" it return the DateTime.Now value and doesn't add 14 days and i guess periodickTask.ExpirationTime doesn't accept the current DateTime as value.

Don't know if it's relevant but I'm testing on a device with 8.1 preview.

Any hints?

Thanks for your help

解决方案

ExpirationTime must be 14 days or less from the current date. And adding 14 days to DateTime.Now could have ExpirationTime greater than 14 days. So try DateTime.Today instead of DateTime.Now

periodicTask.ExpirationTime = DateTime.Today.AddDays(14);


http://msdn.microsoft.com/en-US/library/windowsphone/develop/microsoft.phone.scheduler.periodictask.expirationtime(v=vs.105).aspx


这篇关于DateTime.addDate()不起作用!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆