X++ 的一年中的一周使用 .net 库
static void Job5(Args _args)
{
int i;
System.DateTime netDttm;
System.Int32 intnet;
;
netDttm = new System.DateTime(2011,03,20 ,13,44,55);
intnet = System.Globalization.CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(netDttm, Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Sunday);
i = intnet;
info(int2str(i));
}
我在 vb.net 中尝试过它工作正常,但在 x++(使用 .net lib)中做同样的事情它显示语法错误..我所尝试的只是获取周号。从提供的日期开始。任何见解将不胜感激。
PS 我找到了另一个解决方案,即我在 VS .net 中创建了一个 dll 文件并将其添加到 AX 的引用节点(AOT)。它缩短了 AX 中的代码 static void Job5(Args _args) { weekofyear.wof asd; ; asd = 新的 weekofyear.Wof(); 打印 asd.weekofyr(today()); 暂停; }
static void Job5(Args _args)
{
int i;
System.DateTime netDttm;
System.Int32 intnet;
;
netDttm = new System.DateTime(2011,03,20 ,13,44,55);
intnet = System.Globalization.CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(netDttm, Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Sunday);
i = intnet;
info(int2str(i));
}
I tried the in vb.net it works fine but doing the same in x++(using .net lib) it shows syntax error..All I am trying is to get the week no. from a supplied date. Any insight would be appreciated.
P.S. I found another solution to this which is I created a dll file in VS .net and added this to Reference node(AOT)of AX. It has shorten the code in AXstatic void Job5(Args _args)
{
weekofyear.wof asd;
;
asd = new weekofyear.Wof();
print asd.weekofyr(today());
pause;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个
try this
[请未来的读者注意:以下描述了 Indranil 发布的原始代码中的错误;它不适用于问题中当前的代码,因为 Indranil 修复了此错误。 other 错误已在其他人的另一个答案中得到处理:-)。]
您不应该将字符串作为第一个参数传递给
GetWeekOfYear
;它需要一个 System.DateTime (http://msdn.microsoft.com/en-us/library/system.globalization.calendar.getweekofyear.aspx)。 (至少,在普通 .NET 中确实如此;我不知道 Dynamics AX 是否做了其他一些神奇的事情。我怀疑它确实如此。)(但是,如果您确实想要字符串形式的日期,那些反斜杠
\
应该是正斜杠/
。)[Note to any future readers: The following described an error in the original code Indranil posted; it does not apply to the code currently in the question, because Indranil fixed this error. The other error was dealt with in another answer from someone else :-).]
You shouldn't be passing a string as the first argument to
GetWeekOfYear
; it wants aSystem.DateTime
(http://msdn.microsoft.com/en-us/library/system.globalization.calendar.getweekofyear.aspx). (At least, that's true in ordinary .NET; I don't know whether Dynamics AX does some other magical thing. I doubt it does.)(But if and when you do want a date in the form of a string, those backslashes
\
should be forward slashes/
.)如果您希望此代码支持单词范围的位置,只需确保加载正确的 CultureInfo 即可。加载当前的 CultureInfo 将加载服务器的首选区域性。如果用户是 en-gb 并且服务器是 en-us,则一周的第一天将不正确。
要加载特定的文化信息,您可以简单地执行以下操作:
在选择作为答案的示例中,代码加载文化信息,但文化信息不用作 GetWeekOfYear 方法的参数,这实际上没有任何意义。相反,您可以从cultureinfo 发送设置。
Just make sure you load the correct CultureInfo if you expect this code to support word wide locations. Loading the current CultureInfo will load the servers preferred culture. If the user is en-gb and the server is en-us, you first day of week will be incorrect.
To load a specific cultureinfo you can simply do this:
In the example chosen as answer, the code loads cultureinfo, but the cultureinfo is not used as parameter to the GetWeekOfYear method, which doesnt really make any sense. Instead you could send in the settings from the cultureinfo.