计算财政年度周数的 Javascript 算法

发布于 2024-08-31 16:46:07 字数 165 浏览 5 评论 0原文

我一直在寻找一种 Javascript 算法,它可以为我提供自定义会计年度内给定日期对象的周数。我公司的财政年度从 9 月 1 日开始,到 8 月 31 日结束。

假设今天恰好是 9 月 1 日,我将一个新实例化的 Date 对象传递给此函数;我希望它返回 1。

希望有人能够帮助我。

I have been looking for a Javascript algorithms that gives me the week number of a given Date object within a custom fiscal year. The fiscal year of my company starts on 1 September and ends on 31 August.

Say today happens to be September 1st and I pass in a newly instanced Date object to this function; I would expect it to return 1.

Hopefully someone will be able to help me with it.

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

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

发布评论

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

评论(1

梦纸 2024-09-07 16:46:07

假设您想要日期为 X 的财政年度。

if X > September 1st
  week = week_nr(X) - week_nr(Sept 1st) + 1
else
  // We're in a new year
  week = week_nr(X) + week_nr(Sept 1st) - 1

应该可以了 - 也许新年前后会出现问题,但我想很容易弄清楚。

要获得任何一年内的周数,有很多解决方案。这只是其中之一: http://syn.ac/tech /19/get-the-weeknumber-with-javascript/

Say you want the fiscal year for date X.

if X > September 1st
  week = week_nr(X) - week_nr(Sept 1st) + 1
else
  // We're in a new year
  week = week_nr(X) + week_nr(Sept 1st) - 1

That should do it - maybe there's a problem around new year, but easy enough to figure out I guess.

To get the week number within any year, there are plenty of solutions. Here's just one of them: http://syn.ac/tech/19/get-the-weeknumber-with-javascript/

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