什么是一个好的,简单的方法来计算ISO 8601周数? [英] What is a good, simple way to compute ISO 8601 week number?
问题描述
我希望在Java中做这个,但是对于任何类型的面向对象的语言是很好的。
我相信可以使用Calendar对象(刚刚设置FirstDayOfWeek到星期一和MinimalDaysInFirstWeek到4使其符合ISO 8601)并调用get(Calendar.WEEK_OF_YEAR)。
Suppose I have a date, i.e. year, month and day, as integers. What's a good (correct), concise and fairly readable algorithm for computing the ISO 8601 week number of the week the given date falls into? I have come across some truly horrendous code that makes me think surely there must be a better way.
I'm looking to do this in Java but psuedocode for any kind of object-oriented language is fine.
I believe you can use the Calendar object (just set FirstDayOfWeek to Monday and MinimalDaysInFirstWeek to 4 to get it to comply with ISO 8601) and call get(Calendar.WEEK_OF_YEAR).
这篇关于什么是一个好的,简单的方法来计算ISO 8601周数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!