什么是一个好的,简单的方法来计算ISO 8601周数? [英] What is a good, simple way to compute ISO 8601 week number?

查看:125
本文介绍了什么是一个好的,简单的方法来计算ISO 8601周数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个日期,即年,月和日,作为整数。用于计算 ISO 8601 的一个好的(正确的),简明扼要且可读的算法周号我遇到了一些真正可怕的代码,使我觉得肯定有一个更好的方法。



我希望在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屋!

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