C#插件、Python两种方式计算日期是当年第几周

栏目:云星空知识作者:金蝶来源:金蝶云社区发布:2024-09-16浏览:1

C#插件、Python两种方式计算日期是当年第几周

借助系统日历计算指定日期是当年第几周

C#插件

private void CalcCurWeek()
        {
            DateTime curDate = Convert.ToDateTime(this.View.Model.GetValue("FWeekBDate"));

            if (curDate != null)
            {
                System.Globalization.GregorianCalendar gc = new System.Globalization.GregorianCalendar();

                int weekOfYear = gc.GetWeekOfYear(curDate, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Monday);

                this.View.Model.SetValue("FCurWeek", weekOfYear);
            }
        }

Python代码(亲测有效)

import clr
clr.AddReference('System')
clr.AddReference('System.Globalization')
from System import *
from System.Globalization import *

def DataChanged(e):
    key = e.Field.Key.upper();
    if(key == "FWEEKBDATE"):
        curDate = this.View.Model.GetValue("FWeekBDate");
        if (curDate <> None):
            gc = GregorianCalendar();
            weekOfYear = gc.GetWeekOfYear(curDate, CalendarWeekRule.FirstDay, DayOfWeek.Monday);
            this.View.Model.SetValue("FCurWeek",weekOfYear);

image.webp

特别说明:

gc.GetWeekOfYear(curDate, CalendarWeekRule.FirstDay, DayOfWeek.Monday);

这个方法中的 第三个参数 DayOfWeek.Monday 是指定周从星期几开始


C#插件、Python两种方式计算日期是当年第几周

借助系统日历计算指定日期是当年第几周C#插件private void CalcCurWeek() { DateTime curDate = Convert.ToDateTime(thi...
点击下载文档
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息