在 Visual Basic 中寻找确定的 ISO 周计算器(在 Visual Studio Express 2010 中) [英] Looking for definitive ISO week calculator in Visual Basic (in Visual Studio Express 2010)

查看:28
本文介绍了在 Visual Basic 中寻找确定的 ISO 周计算器(在 Visual Studio Express 2010 中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个明确的标准(即被证明是正确的或经过合理彻底的测试)用于在 Visual Basic 中计算某个日期的 ISO 周(即在 Visual Studio Express 2010 Visual Basic 项目中运行)

I'm looking for a definitive, standard (i.e. certified as being correct or tested reasonably thoroughly) for calculating the ISO week from a date, in Visual Basic (i.e. to run in a Visual Studio Express 2010 Visual Basic project)

(不成功的)研究到目前为止:

  • 我发现了一些面向应用程序的 Visual Basic 例程;依赖于 Excel 环境,一些东西在 Visual Studio Express 2010 Visual Basic 中不存在:

  • I found some routines that were Visual Basic for Applications oriented; reliant on Excel environment, some things not present in Visual Studio Express 2010 Visual Basic:


  • DatePart Visual Basic library function may be useful: http://msdn.microsoft.com/en-us/library/20ee97hz(v=vs.80).aspx - BUT apparently there is a bug: "BUG: Format or DatePart Functions Can Return Wrong Week Number for Last Monday in Year": http://support.microsoft.com/kb/200299 (has this been solved? It's rather old, 2004 so perhaps?)

其他例程:http://forums.devx.com/showthread.php?t=130782 但没有说明它是如何基于 ISO 标准的

Other routines: http://forums.devx.com/showthread.php?t=130782 But doesn't state how it is based on the ISO standard

此外,在 Stack Overflow 上的搜索结果并不是我想要的:https://stackoverflow.com/search?q=iso+week

Also, a search on Stack Overflow gave me results that weren't quite what I was looking for: https://stackoverflow.com/search?q=iso+week

推荐答案

谢谢@assylias - 这个问题的答案非常接近,如果不是我正在寻找的:https://stackoverflow.com/a/1226248/227926

Thanks @assylias - an answer in that question is pretty close, if not exactly what I'm looking for: https://stackoverflow.com/a/1226248/227926

注意使用这个解决方案,我应该补充一点,你需要导入 Calendar 抽象类定义:

Note to use this solution I should add that you need to import the Calendar abstract class defintion:

Imports System.Globalization

然后实例化一个日历实例,我选择了公历,因为它是事实上的标准,但还有其他(文化)选项:

AND then instantiate an Instance of Calendar, I chose Gregorian Calendar as it is the defacto standard, but there are other (cultural) options:

Dim myCalendar As Calendar = New GregorianCalendar

然后,引用解决方案(https://stackoverflow.com/a/1226248/227926):

Then, to quote the solution ( https://stackoverflow.com/a/1226248/227926 ):

可以使用 Calendar.GetWeekOfYear 方法获取周数日期,使用 CalendarWeekRule.FirstFourDayWeek 值指定如何确定周数,以及 DayOfWeek.Monday 来指定第一个工作日.这遵循 ISO 规范.

You can use the Calendar.GetWeekOfYear method to get the week number of a date, with the CalendarWeekRule.FirstFourDayWeek value to specify how the weeks are determined, and DayOfWeek.Monday to specify the first weekday. That follows the ISO specification.

示例:

int week = myCalendar.GetWeekOfYear(DateTime.Today,
CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);

我不会将我的问题标记为重复,因为他们的问题标题根据 C# 中的周数和年份计算一周的开始和结束日期(基于 ISO 规范)"与我的明显不同,而且他们提到 C#(不是 Visual Basic,尽管他们也想要 Visual Basic).

I will not mark my question as a duplicate, because their question title "Calculate the start and end date of a week given the week number and year in C# (based on the ISO specification)" is distinctly different from mine and they mention C# (not Visual Basic although they do want Visual Basic as well).

保留我的问题应该有助于其他人寻找相同的问题.

Keeping my question present should help others in their search for the same.

谢谢!

这篇关于在 Visual Basic 中寻找确定的 ISO 周计算器(在 Visual Studio Express 2010 中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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