获取当前的日历周 [英] Get current calendar week

查看:197
本文介绍了获取当前的日历周的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常的方法是在 actionscript-3

推荐答案

可能是一个好主意,所以你可以得到当前年份的日数,如果需要,你可以使用它来进行更多的基于日期的计算。这是最简单的一个静态数组的int和一些算术...

It might be a good idea to re-cast the problem so you can get the day number in the current year, you'll be able to use it for more date based calculations if you have to. That's most easily done with a static array of ints and a bit of arithmetic...

public static var month_days:Array = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

public static day_num(Date d):int
{
  var cumulative_days:int = 0;
  for (int i = 0; i < d.month; i++)
  {
    cumulative_days += month_days[i];
  }
  cumulative_days += d.date;

  if (add_leap_day(d)) cumulative_days++;

  return cumulative_days;
}

public static week_num(Date d):int
{
  var int day_num = day_num(d);
  return Math.floor(day_num/7);
}

public static function add_leap_day(Date d):boolean
{
  // I'll let you work this out for yourself
  // bear in mind you don't just need to know whether it's a leap year...
}

请注意以下几点:


  • 您的日历周定义是从1月1日开始还是从一年的第一个星期日开始?

  • 你在这一年的闲暇时间做什么,特别是闰年? (52x7!= 365)

  • 您对日历或会计年度感兴趣吗?

  • 一周中每周的定义是相同的吗?有时圣诞节有两个星期或一个额外的月份!

  • Does your definition of a calendar week start on 1st Jan or the first Sunday of the year?
  • What do you do about the spare days in the year, especially leap years? (52x7 != 365)
  • Are you interested in the calendar or fiscal year?
  • Is the definition of a week the same for every week of your year? Sometimes Christmas has two weeks or an extra month!

我写了一个完整的基于日期的财务和常规日历的算术函数库。如果您在任何环境中操作您的用户拥有自己的日历版本 - 即所有金融应用程序,这是一个棘手的问题。

I wound up writing a whole library of date based arithmetic functions for fiscal and regular calendars. It is a tricky problem if you are operating in any environment where your user has their own version of the calendar - i.e. any financial application at all.

这篇关于获取当前的日历周的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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