Flex,如何获得约会的一周?

jav*_*nes 4 apache-flex actionscript date week-number

我在Flex Date对象中找不到一个方法来获取一年中的一周(1到52)

找到这个的最佳方法是什么?对于诸如Java中的JodaTime之类的日期操作,是否有任何有用的flex库.

Ama*_*osh 5

我不知道一个库,但是这个函数会给你一周索引(基于零).

function getWeek(date:Date):Number
{
  var days:Array = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; 
  var year:Number = date.fullYearUTC;
  var isLeap:Boolean = (year % 4 == 0) && (year % 100 != 0)
                       || (year % 100 == 0) && (year % 400 == 0); 
  if(isLeap)
    days[1]++;

  var d = 0;
  //month is conveniently 0 indexed.
  for(var i = 0; i < date.month; i++)
    d += days[i];
  d += date.dateUTC;

  var temp:Date = new Date(year, 0, 1);
  var jan1:Number = temp.dayUTC;
  /**
   * If Jan 1st is a Friday (as in 2010), does Mon, 4th Jan 
   * fall in the first week or the second one? 
   *
   * Comment the next line to make it in first week
   * This will effectively make the week start on Friday 
   * or whatever day Jan 1st of that year is.
   **/
  d += jan1;

  return int(d / 7);
}
Run Code Online (Sandbox Code Playgroud)