Home >php教程 >PHP开发 >Flex actionScript time processing addition returns the added date

Flex actionScript time processing addition returns the added date

高洛峰
高洛峰Original
2016-12-27 17:05:371104browse

public class Util
 {
 public function Util()
 {
 }
 /**
  * 时间处理类,相加返回相加后的date
  * @param datepart 要相加的时间位置
  * @param number 相加的数值
  * @param date 相加的date没有传入是当前时间
  * @return 返回的是相加后的date
  * yxy
  */
 public function dateAdd(datepart:String = "", number:Number = 0, date:Date = null):Date {
  if (date == null) {
  /* Default to current date. */
  date = new Date();
  }
  var returnDate:Date = new Date(date.time);;
  switch (datepart.toLowerCase()) {
  case "fullyear":
  case "month":
  case "date":
  case "hours":
  case "minutes":
  case "seconds":
  case "milliseconds":
   returnDate[datepart] += number;
   break;
  default:
   /* Unknown date part, do nothing. */
   break;
  }
  return returnDate;
 }
 /**
  * 两个date的的时间差
  * @param dataBegin 开始时间
  * @param dateEnd 结束时间
  * @return 返回差的天数
  *
  */
 public function dateDiff(dataBegin:Date,dateEnd:Date):Number{
  var diff:Number = (dateEnd.time-dataBegin.time)/new Number(24*60*60*1000);
  return diff;
 }
 /**
  * 比较两date的大小
  * @param date1
  * @param date2
  * @return date1<date2返回-1,date1=date2返回0,date1>date2返回1。
  *
  */
 public function dateCompare(date1:Date, date2:Date):int { 
  if (Number(date1) < Number(date2)) { 
  return -1
  }
  if (Number(date1) == Number(date2)) { 
  return 0; 
  } 
  return 1; 
 }
 }

For more articles related to flex actionScript time processing addition and returning the added date, please pay attention to the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn