X++ 的一年中的一周使用 .net 库

发布于 2024-10-27 19:06:36 字数 737 浏览 1 评论 0原文

 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 AX
static void Job5(Args _args)
{
weekofyear.wof asd;
;
asd = new weekofyear.Wof();
print asd.weekofyr(today());
pause;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

£冰雨忧蓝° 2024-11-03 19:06:36

试试这个

int i;
     System.DateTime netDttm;
     System.Int32 intnet;
     System.Globalization.CultureInfo cultureInfo;
     System.Globalization.Calendar    calendar;
     System.Globalization.CalendarWeekRule calWeekRule
    ;
     netDttm = new System.DateTime(2011,03,20 ,13,44,55);
     cultureInfo = System.Globalization.CultureInfo::get_CurrentCulture();
     calendar  = cultureInfo.get_Calendar();
     intnet = calendar.GetWeekOfYear(netDttm, System.Globalization.CalendarWeekRule::FirstFourDayWeek, System.DayOfWeek::Sunday);

     i = intnet;

 info(int2str(i));

try this

int i;
     System.DateTime netDttm;
     System.Int32 intnet;
     System.Globalization.CultureInfo cultureInfo;
     System.Globalization.Calendar    calendar;
     System.Globalization.CalendarWeekRule calWeekRule
    ;
     netDttm = new System.DateTime(2011,03,20 ,13,44,55);
     cultureInfo = System.Globalization.CultureInfo::get_CurrentCulture();
     calendar  = cultureInfo.get_Calendar();
     intnet = calendar.GetWeekOfYear(netDttm, System.Globalization.CalendarWeekRule::FirstFourDayWeek, System.DayOfWeek::Sunday);

     i = intnet;

 info(int2str(i));
绅刃 2024-11-03 19:06:36

[请未来的读者注意:以下描述了 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 a System.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 /.)

愛放△進行李 2024-11-03 19:06:36

如果您希望此代码支持单词范围的位置,只需确保加载正确的 CultureInfo 即可。加载当前的 CultureInfo 将加载服务器的首选区域性。如果用户是 en-gb 并且服务器是 en-us,则一周的第一天将不正确。

要加载特定的文化信息,您可以简单地执行以下操作:

System.Globalization.CultureInfo arCul = new System.Globalization.CultureInfo("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:

System.Globalization.CultureInfo arCul = new System.Globalization.CultureInfo("en-US");

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文