DateTime.addDate()不起作用! [英] DateTime.addDate() not working!
问题描述
大家好,如果我在"调试模式"中运行应用程序,我正在使用后台代理处理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);
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);
这篇关于DateTime.addDate()不起作用!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!