# Builtin - 基础 / 日期时间 ## `now()` 声明:function 返回TDateTime类型的当前日期和时间,与系统参数无关。 返回:tdatetime ### 示例 ```tsl return now(); // 输出40763.59 ``` ## `date()` 声明:function 返回TDateTime类型的当前日期,时间部分为0,与系统参数无关。 返回:tdatetime ### 示例 ```tsl // 当前的日期 return date(); // 输出41656 ``` ## `encodeDate(year, month, day)` 声明:function 将参数指定的Year,Month,Day作为年、月、日组成一个TDateTime类型返回 | 参数 | 类型 | 说明 | | ------- | ------- | -------- | | `year` | integer | 整数,年 | | `month` | integer | 整数,月 | | `day` | integer | 整数,日 | 返回:tdatetime ### 示例 ```tsl date := encodeDate(2011, 8, 6); return date; // 输出:40761 ``` ## `tryStrToDate(s, value)` 声明:function 将字符串S转换成TDateTime类型的日期并存到参数Value中。如果转换成功,则返回真,否则返回假 | 参数 | 类型 | 说明 | | ------- | --------- | ---------------------------------------- | | `s` | string | 字符串,日期的字符串类型,如"2014-01-17" | | `value` | tdatetime | 日期,转化后的日期,返回值 | 返回:bool ### 示例 ```tsl if tryStrToDate("2010-02-04 ", date) then return date; // 输出40213 ``` ## `strToDateTimeDef(s, default)` 声明:function 将字符串S转换成TDateTime类型的日期和时间,如果转换不成功,则返回Default指定的默认日期和时间。 | 参数 | 类型 | 说明 | | --------- | --------- | ----------------------------------------------------- | | `s` | string | 字符串,日期时间的字符串类型,如"2014-01-17 10:00:00" | | `default` | tdatetime | TDateTime类型,默认值 | 返回:tdatetime ### 示例 ```tsl return strToDateTimeDef("2011-08-08 16:61:16 ", now()); // 输出当前系统日期时间 ``` ## `currentYear()` 声明:function 返回整数类型的当前年份,与设置的pn_date无关。 返回:integer ### 示例 ```tsl return currentYear(); // 输出2011 ``` ## `strToTimeDef(s, default)` 声明:function 将字符串S转换成TDateTime类型的时间,如果转换不成功,则返回Default指定的默认时间。 | 参数 | 类型 | 说明 | | --------- | --------- | -------------------------------------- | | `s` | string | 字符串,时间的字符串类型,如"15:20:34" | | `default` | tdatetime | TDateTime类型,默认值 | 返回:tdatetime ### 示例 ```tsl time := strToTimeDef("15:61:34 ", time()); return time; // 输出当前系统时间 ``` ## `formaTDateTime(format, date_time)` 声明:function 根据参数Format给定的格式串将参数DateTime转换成字符串类型返回 | 参数 | 类型 | 说明 | | ----------- | --------- | ------------------------------- | | `format` | string | 字符串,格式串 | | `date_time` | tdatetime | TDateTime类型,日期时间,默认值 | 返回:string ### 示例 ```tsl return formaTDateTime("C", now()); // 输出2011-08-08 16:27:08 return formaTDateTime("Dddddd", now()); // 输出2011年8月8日 ``` ## `isLeapYear(year)` 声明:function 返回参数指定的年份Year是否是个闰年,与系统参数无关。 | 参数 | 类型 | 说明 | | ------ | ------- | -------------- | | `year` | integer | 整数,年,年份 | 返回:bool ### 示例 ```tsl return isLeapYear(2000); // 输出1 return isLeapYear(2011); // 输出0 ``` ## `gmtToLocalDateTime(s)` 声明:function 将GMT串转换为日期。 | 参数 | 类型 | 说明 | | ---- | ------ | --------------------------- | | `s` | string | 字符串,GMT格式的时间字符串 | 返回:tdatetime ### 示例 ```tsl gmt := "Wed, 01 Jan 2014 10:00:00 GMT "; datetime := gmtToLocalDateTime(gmt); return datetime; // 输出:41640.75 (时间为2014-01-01 18:00:00) ``` ## `strToDateDef(s, default)` 声明:function 将字符串S转换成TDateTime类型的日期,如果转换不成功,则返回Default指定的默认日期。 | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------------------------- | | `s` | string | 字符串,日期的字符串类型,如"2014-01-17" | | `default` | tdatetime | TDateTime类型,默认值 | 返回:tdatetime ### 示例 ```tsl return strToDateDef("2010-02-30", date()); // 转换失败输出当前日期40763 ``` ## `tryStrToDateTime(s, value)` 声明:function 将字符串S转换成TDateTime类型的日期和时间并存到参数Value中。如果转换成功,则返回真,否则返回假 | 参数 | 类型 | 说明 | | ------- | --------- | ---------------------------------------- | | `s` | string | 字符串,日期的字符串类型,如"2014-01-17" | | `value` | tdatetime | 日期时间,返回值 | 返回:bool ### 示例 ```tsl if tryStrToDateTime("2010-02-04 16:11:35 ", datetime) then return datetime; // 输出40213.67 ``` ## `isValidDateDay(a_year)` 声明:function 判断参数指定的年以及此年的第ADayOfYear天是否是有效日期。返回值类型是布尔型真假值 | 参数 | 类型 | 说明 | | -------- | ------- | -------------------- | | `a_year` | integer | 整数,年,指定的年份 | 返回:bool ### 示例 ```tsl if isValidDateDay(2010, 345) then return "valid " else return "not valid "; // 输出 valid ``` ## `today()` 声明:function 返回今天的日期,不含时间部分 返回:tdatetime ### 示例 ```tsl datetime := today(); return dateToStr(datetime); // 输出2011-08-08 ``` ## `yesterday()` 声明:function 返回昨天的日期,不含时间部分 返回:tdatetime ### 示例 ```tsl datetime := yesterday(); return dateToStr(datetime); // 输出2011-08-07 ``` ## `tomorrow()` 声明:function 返回明天的日期,不含时间部分 返回:tdatetime ### 示例 ```tsl datetime := tomorrow(); return dateToStr(datetime); // 输出2011-08-09 ``` ## `weekOfTheMonth()` 声明:function (参考文档未提供简述。) 返回:any ## `recodeSecond(a_value)` 声明:function 将参数ASecond指定的秒数(0至59)替换掉参数AValue中的相应的秒数信息,得到的日期时间类型返回 | 参数 | 类型 | 说明 | | --------- | --------- | ------------ | | `a_value` | tdatetime | 日期时间类型 | 返回:tdatetime ### 示例 ```tsl new_time := recodeSecond(strToDateTime("2011-08-10 12:12:12"), 9); return dateTimeToStr(new_time); // 输出: 2011-08-10 12:12:09 ``` ## `startOfADay(a_year, a_month, a_day, a_year)` 声明:function 返回由参数Ayear、Amonth、ADay指定的年月日的最初时间,也就是将日期设定为当天,将时间部分置0 | 参数 | 类型 | 说明 | | --------- | ------- | --------------------------------- | | `a_year` | integer | 整数,年,定义域是[1,9999] | | `a_month` | integer | 整数,月,定义域是[1,12] | | `a_day` | integer | 整数,日,定义域是[1,31] | | `a_year` | integer | 整数,年,年份,定义域是[1,9999] | 返回:tdatetime ### 示例 ```tsl year := startOfADay(2011, 8, 8); return dateTimeToStr(year); // 输出: 2011-08-08 ``` ## `endOfADay(a_year, a_month, a_day, a_year)` 声明:function 返回由参数Ayear、Amonth、ADay指定的年月日的结束时间,也就是将日期设定为当天,将时间部分置为下午11:59:59:999,返回类型是TDateTime | 参数 | 类型 | 说明 | | --------- | ------- | -------------------------------- | | `a_year` | integer | 整数,年,年份,定义域是[1,9999] | | `a_month` | integer | 整数,月,月份,定义域是[1,12] | | `a_day` | integer | 整数,日,日期,定义域是[1,31] | | `a_year` | integer | 整数,年,年份,定义域是[1,9999] | 返回:tdatetime ### 示例 ```tsl year := endOfADay(2015, 1, 5); return dateTimeToStr(year); // 输出: 2015-01-05 23:59:59 ``` ## `milliSecondSpan(a_now, athen)` 声明:function 得到参数ANow和参数AThen之间的相距的毫秒数 | 参数 | 类型 | 说明 | | ------- | --------- | ---------------------- | | `a_now` | tdatetime | 日期时间类型,日期时间 | | `athen` | tdatetime | 日期时间类型,日期时间 | 返回:real ### 示例 ```tsl beg_t := strToDateTime('2010-08-01 00:00:00'); end_t := strToDateTime('2012-08-01 12:00:00'); milliseconds := secondSpan(beg_t, end_t); return milliseconds; // 输出: 63201600000 ``` ## `tryStrToTime(s)` 声明:function 将字符串S转换成TDateTime类型的时间并存到参数Value中。如果转换成功,则返回真,否则返回假 | 参数 | 类型 | 说明 | | ---- | ------ | ---------------------------------------- | | `s` | string | 字符串,日期的字符串类型,如"2014-01-17" | 返回:bool ### 示例 ```tsl if tryStrToTime("15:52:35", time) then return time; // 输出0.66 ``` ## `dateTimeToString(result, format, date_time)` 声明:function 根据参数Format给定的格式串将参数DateTime转换成字符串类型存到参数Result中,其中格式串的使用参照FormaTDateTime函数 | 参数 | 类型 | 说明 | | ----------- | ---- | ------------------------------- | | `result` | | 字符串,返回值 | | `format` | | 字符串,格式串 | | `date_time` | | TDateTime类型,需转换的日期时间 | 返回:string ### 示例 ```tsl dateTimeToString(result, 'YYYY-MM-DD HH:NN:SS', now()); return result; // 输出当期系统日期时间 ``` ## `encodeTime(hour, min, sec, m_sec)` 声明:function 将参数指定的Hour, Min, Sec, MSec: Integer作为小时、分钟、秒、毫秒组成一个TDateTime类型返回 | 参数 | 类型 | 说明 | | ------- | ------- | ---------- | | `hour` | integer | 整数,小时 | | `min` | integer | 整数,分钟 | | `sec` | integer | 整数,秒 | | `m_sec` | integer | 整数,毫秒 | 返回:tdatetime ### 示例 ```tsl time1 := encodeTime(12, 35, 35, 100); return time1; // 输出:0.52471(12:35:35.1) ``` ## `tryEncodeDate(year, month, day, date)` 声明:function 将参数指定的Year,Month,Day作为年、月、日组成一个TDateTime类型寸到参数Date中。如果转换成功,函数返回真,否则返回假 | 参数 | 类型 | 说明 | | ------- | --------- | ------------ | | `year` | integer | 整数,年 | | `month` | integer | 整数,月 | | `day` | integer | 整数,日 | | `date` | tdatetime | 日期,返回值 | 返回:bool ### 示例 ```tsl if tryEncodeDate(2011, 12, 25, date) then return date; // 输出:40902 else return "encode error"; // 输出 encode error if tryEncodeDate(2011, 12, 32, date) then return date else return "encode error"; // 输出 encode error ``` ## `tryEncodeTime(hour, min, sec, m_sec, time)` 声明:function 将参数指定的Hour, Min, Sec, MSec: Integer作为小时、分钟、秒、毫秒组成一个TDateTime类型寸到参数Time中。如果转换成功,函数返回真,否则返回假 | 参数 | 类型 | 说明 | | ------- | --------- | ---------------- | | `hour` | integer | 整数,小时 | | `min` | integer | 整数,分钟 | | `sec` | integer | 整数,秒 | | `m_sec` | integer | 整数,毫秒 | | `time` | tdatetime | 日期,组成的日期 | 返回:bool ### 示例 ```tsl if tryEncodeTime(12, 20, 30, 200, time) then return time // 输出:0.51 else return "eccode error "; ``` ## `decodeDate(date_time, year, month, day)` 声明:function 将参数指定的TDateTime类型时间DateTime的年、月、日信息分别存到参数Year,Month,Day中 | 参数 | 类型 | 说明 | | ----------- | --------- | --------------------------------- | | `date_time` | tdatetime | TDateTime类型,日期时间(输入值) | | `year` | integer | 整数,年(输出值) | | `month` | integer | 整数,月(输出值) | | `day` | integer | 整数,日(输出值) | 返回:integer ### 示例 ```tsl decodeDate(intToDate(20140115), year, month, day); return array(year, month, day ); // 输出array(2014,1,15) ``` ## `decodeDateFully(date_time, year, month, day, dow)` 声明:function 将参数指定的TDateTime类型时间DateTime的年、月、日以及星期几的信息分别存到参数Year,Month,Day,DOW中。如果是闰年,返回真,否则返回假。如果是公元前的年份,则所有参数返回0 | 参数 | 类型 | 说明 | | ----------- | --------- | -------------------------------------------------------------------------------- | | `date_time` | tdatetime | TDateTime类型,日期时间 | | `year` | integer | 整数,年,输出值 | | `month` | integer | 整数,月,输出值 | | `day` | integer | 整数,日,输出值 | | `dow` | integer | 整数,星期,输出值;结果和DayOfWeek一致,非ISO8601标准。1-7,星期天为1,星期六为7 | 返回:bool ### 示例 ```tsl flag := decodeDateFully(intToDate(20140115), year, month, day, dow); fname := ifThen(1, '闰年', '平年'); return array(year, month, day, dow, fname); // 输出:array(2014,1,15,4,'闰年') ``` ## `decodeTime(date_time, hour, min, sec, m_sec)` 声明:function 将参数指定DateTime的时间的小时、分钟、秒、毫秒分别存到参数Hour, Min, Sec, MSec中。 | 参数 | 类型 | 说明 | | ----------- | --------- | ----------------------- | | `date_time` | tdatetime | TDateTime类型,日期时间 | | `hour` | integer | 整数,小时,输出值 | | `min` | integer | 整数,分钟,输出值 | | `sec` | integer | 整数,秒,输出值 | | `m_sec` | integer | 整数,毫秒,输出值 | 返回:integer ### 示例 ```tsl decodeTime(strToTime("13:33:45.500"), hour, min, sec, msec); return array(hour, min, sec, msec); // 返回 array(13,33,45,500) ``` ## `dayOfWeek(date_time)` 声明:function 返回星期几,1代表星期天,7代表星期六。非ISO8601标准,如果需要使用ISO8601标准,请使用DayOfTheWeek | 参数 | 类型 | 说明 | | ----------- | --------- | ----------------------- | | `date_time` | tdatetime | TDateTime类型,日期时间 | 返回:integer ### 示例 ```tsl dow := dayOfWeek(encodeDate(2011, 8, 8)); return dow; // 输出:2 ``` ## `incAMonth(year, month, day, number_of_months)` 声明:function 返回参数Year、Month、Day指定年、月、日的时间之后NumberOfMonths个月的时间,并把这个时间的年、月、日存到参数Year、Month、Day中。 | 参数 | 类型 | 说明 | | ------------------ | ------- | -------------- | | `year` | integer | 整数,年,年份 | | `month` | integer | 整数,月,月份 | | `day` | integer | 整数,日,日期 | | `number_of_months` | integer | 整数,月数 | 返回:tdatetime ### 示例 ```tsl year := 2011; month := 8; day := 8; incAMonth(year, month, day, 4); return encodeDate(year, month, day); // 输出40885 ``` ## `dateToStr(date_time)` 声明:function 将TDateTime类型的参数DateTime的日期部分转换成字符串,格式是短日期格式 | 参数 | 类型 | 说明 | | ----------- | --------- | ----------------------- | | `date_time` | tdatetime | TDateTime类型,日期时间 | 返回:string ### 示例 ```tsl end_t := intToDate(20140117); return dateToStr(end_t); // 输出 2014-01-17 ``` ## `timeToStr(date_time)` 声明:function 将TDateTime类型的参数DateTime的时间部分转换成字符串,格式是长时间格式 | 参数 | 类型 | 说明 | | ----------- | --------- | ----------------------- | | `date_time` | tdatetime | TDateTime类型,日期时间 | 返回:string ### 示例 ```tsl // 输入时间或者日期时间 return timeToStr(0.5); return timeToStr(now()); ``` ## `dateTimeToStr(date_time)` 声明:function 将TDateTime类型的参数DateTime的日期和时间转换成字符串,格式是短日期加长时间格式 | 参数 | 类型 | 说明 | | ----------- | --------- | ----------------------- | | `date_time` | tdatetime | TDateTime类型,日期时间 | 返回:string ### 示例 ```tsl end_t := now(); return dateTimeToStr(end_t); // 输出当前系统日期时间 ``` ## `dateTimeToInternetStr(date, to_gmt)` 声明:function 将日期转为Internet格式字符串Friday, 13Jun2008 22:27:04 +0800,当ToGMT为真时,采用GMT时间格式。 | 参数 | 类型 | 说明 | | -------- | --------- | ---------------------------- | | `date` | tdatetime | 日期时间类型,用于转换的时间 | | `to_gmt` | bool | 布尔,是否采用GMT时间格式 | 返回:string ### 示例 ```tsl end_t := strToDateTime('2014-01-01 10:00:00'); datetime := dateTimeToInternetStr(end_t, 0); return datetime; // 输出Wed, 1 Jan 2014 10:00:00 +0800 ``` ## `dateTimeGmtToCookieStr(date)` 声明:function 将日期时间(GMT时间)转为Cookie格式字符串Fri, 13-Jun-2008 23:01:56 GMT。 | 参数 | 类型 | 说明 | | ------ | --------- | ---------------------------- | | `date` | tdatetime | 日期时间类型,用于转换的时间 | 返回:string ### 示例 ```tsl end_t := strToDateTime('2014-01-01 10:00:00'); datetime := dateTimeGmtToCookieStr(end_t); return datetime; // 输出Wed, 01-Jan-2014 10:00:00 GMT ``` ## `dateTimeGmtToHttpStr(date)` 声明:function 将日期时间(GMT时间)转为HTTP格式字符串Fri, 13 Jun 2008 23:01:56 GMT。 | 参数 | 类型 | 说明 | | ------ | --------- | ------------------------ | | `date` | tdatetime | 日期时间,用于转换的时间 | 返回:string ### 示例 ```tsl end_t := strToDateTime('2014-01-01 10:00:00'); datetime := dateTimeGmtToHttpStr(end_t); return datetime; // 输出:Wed, 01 Jan 2014 10:00:00 GMT ``` ## `dateToInt(date_time)` 声明:function 将日期类型的EndT转换成整数类型 | 参数 | 类型 | 说明 | | ----------- | --------- | -------- | | `date_time` | tdatetime | 日期类型 | 返回:integer ### 示例 ```tsl date_time := 40559; return dateToInt(date_time); // 输出:20110116 ``` ## `intToDate(rdate)` 声明:function 将整型的日期转换成日期类型的日期 | 参数 | 类型 | 说明 | | ------- | ------- | ---- | | `rdate` | integer | 整型 | 返回:tdatetime ### 示例 ```tsl rdate := 20110116; return intToDate(rdate); // 输出: 40559 ``` ## `isInLeapYear(a_value)` 声明:function 判断指定的AValue是否是一个闰年。返回一个布尔真假值 | 参数 | 类型 | 说明 | | --------- | --------- | ------------ | | `a_value` | tdatetime | 日期时间类型 | 返回:bool ### 示例 ```tsl if isInLeapYear(date) then return "this year is a leap year " else return "this year is not a leap year "; ``` ## `isPm(a_value)` 声明:function 判断指定的AValue是否处于下午,就是超过了12:00。返回一个布尔真假值 | 参数 | 类型 | 说明 | | --------- | --------- | ------------ | | `a_value` | tdatetime | 日期时间类型 | 返回:bool ### 示例 ```tsl if isPm(time()) then return "is PM " else return "is AM "; ``` ## `isValidDate(a_year, a_month, a_day)` 声明:function 判断参数指定的的年AYear,月AMonth,日Aday是否是一个有效日期,返回值类型是布尔型真假值 | 参数 | 类型 | 说明 | | --------- | ------- | -------------------- | | `a_year` | integer | 整数,年,指定的年份 | | `a_month` | integer | 整数,月,指定的月份 | | `a_day` | integer | 整数,日,指定的日期 | 返回:bool ### 示例 ```tsl if isValidDate(2011, 8, 34) then return "right " else return "wrong "; // 输出 wrong ``` ## `isValidTime(a_hour, a_minute, a_second, a_milli_second)` 声明:function 判断参数指定的时间是否有效,包括小时AHour,分钟AMinute,秒ASecond,毫秒AmilliSecond,返回值类型是布尔型真假值 | 参数 | 类型 | 说明 | | ---------------- | ------- | ---------- | | `a_hour` | integer | 整数,小时 | | `a_minute` | integer | 整数,分钟 | | `a_second` | integer | 整数,秒 | | `a_milli_second` | integer | 整数,毫秒 | 返回:bool ### 示例 ```tsl if isValidTime(17, 48, 45, 678) then return "right time " else return "wrong time "; // 输出 right time ``` ## `isValidDateTime(a_year, a_month, a_day, a_hour, a_month, a_second, amilli_second)` 声明:function 判断参数指定的日期以及时间是否有效,包括小时AHour ,分钟AMinute,秒ASecond,毫秒AmilliSecond,返回值类型是布尔型真假值。 | 参数 | 类型 | 说明 | | --------------- | ------- | -------------------- | | `a_year` | integer | 整数,年,指定的年份 | | `a_month` | integer | 整数,月,指定的月份 | | `a_day` | integer | 整数,日,指定的日期 | | `a_hour` | integer | 整数,小时,小时 | | `a_month` | integer | 整数,月,分钟 | | `a_second` | integer | 整数,秒 | | `amilli_second` | integer | 整数,毫秒 | 返回:bool ### 示例 ```tsl if isValidDateTime(2011, 8, 8, 17, 57, 56, 245) then return "right " else return "wrong "; // 输出 right ``` ## `isValidDateWeek(a_year, aweek_of_year, aday_of_week)` 声明:function 判断参数指定的年以及此年的第AweekOfYear周以及此周的第AdayOfWeek天是否是有效日期。返回值类型是布尔型真假值 | 参数 | 类型 | 说明 | | --------------- | ------- | ----------------------------- | | `a_year` | integer | 整数,指定的年份 | | `aweek_of_year` | integer | 整数,表示在Ayear年份的第几周 | | `aday_of_week` | integer | 整数,表示指定周的第几天 | 返回:bool ### 示例 ```tsl if isValidDateWeek (2010, 15, 4) then return "valid " else return "not valid "; // 输出 valid ``` ## `isValidDateMonthWeek(a_year, a_month, aweek_of_month, aday_of_week)` 声明:function 判断参数指定的年以及此年的第Amonth月以及此月的第AWeekOfMonth周以及此周的第AdayOfWeek天是否是有效日期。返回值类型是布尔型真假值 | 参数 | 类型 | 说明 | | ---------------- | ------- | ----------------------------------- | | `a_year` | integer | 整数,年份 | | `a_month` | integer | 整数,月份 | | `aweek_of_month` | integer | 整数,表示在Ayear年Amonth月的第几周 | | `aday_of_week` | integer | 整数,表示指定周的第几天 | 返回:bool ### 示例 ```tsl if isValidDateMonthWeek(2000, 10, 2, 3) then return "valid " else return "not valid "; // 输出 valid ``` ## `weeksInYear(a_value)` 声明:function 返回AValue所在的年份共含有多少个周。周数的认定是依据ISO8601的标准,关于此标准的解释请参阅附注。 | 参数 | 类型 | 说明 | | --------- | --------- | -------- | | `a_value` | tdatetime | 日期类型 | 返回:integer ### 示例 ```tsl num := weeksInYear (date()); return num; // 输出52 ``` ## `weeksInAYear(a_year)` 声明:function 返回年份AYear共含有多少个周。周数的认定是依据ISO8601的标准,关于此标准的解释请参阅附注。 | 参数 | 类型 | 说明 | | -------- | ------- | ------------------------- | | `a_year` | integer | 整数,年,定义域[1,9999] | 返回:integer ### 示例 ```tsl num := weeksInAYear (2010); return num; // 输出52 ``` ## `daysInYear(a_value)` 声明:function 返回AValue所在的年份共含有多少天。参数: | 参数 | 类型 | 说明 | | --------- | --------- | -------- | | `a_value` | tdatetime | 日期时间 | 返回:integer ### 示例 ```tsl days := daysInYear (date()); return days; // 输出365 ``` ## `daysInAYear(a_year)` 声明:function 返回年份AYear共含有多少天。 | 参数 | 类型 | 说明 | | -------- | ------- | ------------------------- | | `a_year` | integer | 整数,年,定义域[1,9999] | 返回:integer ### 示例 ```tsl days := daysInAYear (2010); return days; // 输出365 ``` ## `daysInMonth(a_value)` 声明:function 返回AValue所在的月份共含有多少天。 | 参数 | 类型 | 说明 | | --------- | --------- | ---- | | `a_value` | tdatetime | 日期 | 返回:integer ### 示例 ```tsl days := daysInMonth (intToDate(20131201)); return days; // 输出31 ``` ## `daysInAMonth(a_year, a_month)` 声明:function 返回由Ayear指定的年的第Amonth月共含有多少天。 | 参数 | 类型 | 说明 | | --------- | ------- | ------------------------- | | `a_year` | integer | 整数,年,定义域[1,9999] | | `a_month` | integer | 整数,月,定义域[1,12] | 返回:integer ### 示例 ```tsl days := daysInAMonth (2010, 2); return days; // 输出28 ``` ## `isToday(a_value)` 声明:function 判断参数AValue的日期是否在今天,返回值类型是布尔型真假值,如果在今天为真,否则为假 | 参数 | 类型 | 说明 | | --------- | --------- | -------- | | `a_value` | tdatetime | 日期类型 | 返回:bool ### 示例 ```tsl today := today(); aday := today+2; if isToday(aday) then return "aday is today " else return "aday is not today "; // 输出aday is not today ``` ## `isSameDay(a_value, a_basis)` 声明:function 判断参数AValue和参数Abasis是否在同一天发生。返回值类型是布尔型真假值,如果是同一天,返回真,否则为假 | 参数 | 类型 | 说明 | | --------- | --------- | -------- | | `a_value` | tdatetime | 日期类型 | | `a_basis` | tdatetime | 日期类型 | 返回:bool ### 示例 ```tsl today := today(); aday := today+2; if isSameDay(aday, today) then return "sameday " else return " not sam day"; // 输出:not sameday ``` ## `dateOf(a_value)` 声明:function 截取日期时间类型的日期数据 | 参数 | 类型 | 说明 | | --------- | --------- | ------------ | | `a_value` | tdatetime | 日期时间类型 | 返回:tdatetime ### 示例 ```tsl return dateOf(now()); // 返回今天的日期 ``` ## `timeOf(a_value)` 声明:function 返回一个只含有时间信息的TDateTime类型,天数部分设为0,就是1899年12月30日 | 参数 | 类型 | 说明 | | --------- | --------- | ------------ | | `a_value` | tdatetime | 日期时间类型 | 返回:tdatetime ### 示例 ```tsl return timeOf (now()); // 返回当前所处的时间点 // 截取某个日期时间的时间点 end_t := strToDateTime("2014-01-17 10:00:00"); return timeOf(end_t); // 返回0.4167 ``` ## `yearOf(a_value)` 声明:function 返回参数AValue中包含的年份信息。值域[1,9999] | 参数 | 类型 | 说明 | | --------- | --------- | -------- | | `a_value` | tdatetime | 日期类型 | 返回:integer ### 示例 ```tsl year := yearOf(strToDate('2010-08-08')); return year; // 输出: 2010 ``` ## `monthOf(a_value)` 声明:function 返回参数AValue中包含的月份信息。值域[1,12] | 参数 | 类型 | 说明 | | --------- | --------- | -------------- | | `a_value` | tdatetime | 日期类型,日期 | 返回:integer ### 示例 ```tsl month := monthOf(strToDate('2010-08-08')); return month; // 输出: 8 ``` ## `dayOf(a_value)` 声明:function 返回参数AValue中包含的日期信息。值域[1,31] | 参数 | 类型 | 说明 | | --------- | --------- | -------------- | | `a_value` | tdatetime | 日期类型,日期 | 返回:integer ### 示例 ```tsl hour := dayOf(strToDateTime('2011-08-08 11:22:06')); return hour; // 输出: 8 ``` ## `hourOf(a_value)` 声明:function 返回参数AValue中包含的小时信息。值域[0,23],同函数是HourOfTheDay | 参数 | 类型 | 说明 | | --------- | --------- | ------------------ | | `a_value` | tdatetime | 日期类型,日期时间 | 返回:integer ### 示例 ```tsl hour := hourOf(strToDateTime('2011-08-08 11:22:06')); return hour; // 输出: 11 ``` ## `minuteOf(a_value)` 声明:function 返回参数AValue中包含的分钟信息。值域[0,59] | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl minute := minuteOf(strToDateTime('2011-08-08 11:22:06')); return minute; // 输出: 22 ``` ## `secondOf(a_value)` 声明:function 返回参数AValue中包含的秒信息。值域[0,59], | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl second := secondOf(strToDateTime('2011-08-08 11:22:06')); return second; // 输出: 6 ``` ## `milliSecondOf(a_value)` 声明:function 返回参数AValue中包含的毫秒信息。值域[0,999], | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl millisecond := milliSecondOf(strToDateTime('2011-08-08 11:22:06.990')); return millisecond; // 输出: 990 ``` ## `startOfTheYear(a_value)` 声明:function 返回参数AValue中包含的年份的最初时间,将日期设定为1月1日,无时间部分。 | 参数 | 类型 | 说明 | | --------- | --------- | -------------- | | `a_value` | tdatetime | 日期类型,日期 | 返回:tdatetime ### 示例 ```tsl d_time := startOfTheYear(strToDateTime('2011-08-08 11:22:06.990')); return dateTimeToStr(d_time); // 输出: 2011-01-01 ``` ## `endOfTheYear(a_value)` 声明:function 返回参数AValue中所属年的最后一个年自然日的日期时间,如果输入的参数AValue中包含时间数据,则返回的日期中也包含时间数据;否则无时间部分。 | 参数 | 类型 | 说明 | | --------- | --------- | ------------------ | | `a_value` | tdatetime | 日期类型,日期时间 | 返回:tdatetime ### 示例 ```tsl year := endOfTheYear(strToDateTime('2011-08-08 11:22:06.990')); return dateTimeToStr(year); // 输出: 2011-12-31 23:59:59 ``` ## `startOfAYear(a_year)` 声明:function 返回参数Ayear指定的年份的年初时间,返回的年初日期无时间部分 | 参数 | 类型 | 说明 | | -------- | ------- | --------------------------- | | `a_year` | integer | 整数,年,定义域是[1,9999] | 返回:tdatetime ### 示例 ```tsl year := startOfAYear(2011); return dateTimeToStr(year); // 输出: 2011-01-01 ``` ## `endOfAYear(a_year)` 声明:function 返回参数Ayear指定的年份的结束时间,将日期设定为12月31日,时间部分为23:59:59:999,返回类型是日期时间 | 参数 | 类型 | 说明 | | -------- | ------- | --------------------------- | | `a_year` | integer | 整数,年,定义域是[1,9999] | 返回:tdatetime ### 示例 ```tsl year := endOfAYear(2011); return dateTimeToStr(year); // 输出: 2011-12-31 23:59:59 ``` ## `startOfTheMonth(a_value)` 声明:function 返回参数AValue指定的年月的月初时间,将日期设定为当月的第1自然日,时间部分为0。 | 参数 | 类型 | 说明 | | --------- | --------- | ----------------------- | | `a_value` | tdatetime | TDateTime类型,日期时间 | 返回:tdatetime ### 示例 ```tsl year := startOfTheMonth(strToDateTime('2011-08-08 12:48:22.990')); return dateTimeToStr(year); // 输出: 2011-08-01 ``` ## `endOfTheMonth(a_value)` 声明:function 返回参数AValue指定的年月的月结束时间,将日期设定为当月最后1个自然日,将时间部分为23:59:59:999,返回类型是TDateTime | 参数 | 类型 | 说明 | | --------- | --------- | ----------------------- | | `a_value` | tdatetime | TDateTime类型,日期时间 | 返回:tdatetime ### 示例 ```tsl year := endOfTheMonth(strToDateTime('2011-08-08 12:48:22.990')); return dateTimeToStr(year); // 输出: 2011-08-31 23:59:59 ``` ## `startOfAMonth(a_year, a_month)` 声明:function 返回参数AYear指定的年份的AMonth月的最初时间,将日期设定为当月第1自然日,时间部分为0 | 参数 | 类型 | 说明 | | --------- | ------- | --------------------------- | | `a_year` | integer | 整数,年,定义域是[1,9999] | | `a_month` | integer | 整数,月,定义域是[1,12] | 返回:tdatetime ### 示例 ```tsl tdate := startOfAMonth(2011, 08); return dateTimeToStr(tdate); // 输出: 2011-08-01 ``` ## `endOfAMonth(a_year, a_month)` 声明:function 返回参数AYear指定的年份的AMonth月的最初时间,将日期设定为当月最后一日,将时间部分置为下午11:59:59:999,返回类型是TDateTime | 参数 | 类型 | 说明 | | --------- | ------- | --------------------------- | | `a_year` | integer | 整数,年,定义域是[1,9999] | | `a_month` | integer | 整数,月,定义域是[1,12] | 返回:tdatetime ### 示例 ```tsl ttime := endOfAMonth(2011, 08); return dateTimeToStr(ttime); // 输出: 2011-08-31 23:59:59 ``` ## `startOfTheWeek(a_value)` 声明:function 返回参数AValue指定的时间所属周的最初时间,将日期设定为当周的第1个自然日,时间部分为0 | 参数 | 类型 | 说明 | | --------- | --------- | ----------------------- | | `a_value` | tdatetime | TDateTime类型,日期时间 | 返回:tdatetime ### 示例 ```tsl year := startOfTheWeek(strToDateTime('2011-08-07')); return dateTimeToStr(year); // 输出: 2011-08-01 // 其中2011-08-07是星期天,2011-08-01是星期一 ``` ## `endOfTheWeek(a_value)` 声明:function 返回参数AValue指定的时间所属周的结束时间,将日期设定为当周的最后1个自然日,将时间部分置为下午11:59:59:999,返回类型是TDateTime | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:tdatetime ### 示例 ```tsl year := endOfTheWeek(strToDateTime('2011-08-01')); return dateTimeToStr(year); // 输出: 2011-08-07 23:59:59 // 其中2011-08-01是星期一,输出结果2011-08-07是星期天 ``` ## `startOfAWeek(a_year, aweek_of_year, aday_of_week)` 声明:function 返回参数AYear指定的年份的第AWeekOfYear周的最初时间,将日期设定为当周的第1日,无时间部分。 | 参数 | 类型 | 说明 | | --------------- | ------- | ----------------------------------------------- | | `a_year` | integer | 整数,年,定义域是[1,9999] | | `aweek_of_year` | integer | 整数,年,表示当年的第几周 | | `aday_of_week` | integer | 整数,表示当周的第几天,默认为1,既一周的最开始 | 返回:tdatetime ### 示例 范例一: ```tsl // 取当年的第一个完整周 year := startOfAWeek(2011, 1, 1); return dateTimeToStr(year); // 输出: 2011-01-03 ``` 范例二: ```tsl year := startOfAWeek(2011, 2, 1); return dateTimeToStr(year); // 输出:2011-01-10 ``` ## `endOfAWeek(a_year, aweek_of_year, aday_of_week)` 声明:function 返回参数AYear指定的年份的第AWeekOfYear周的结束时间,如果不设定参数ADayOfWeek,则取当周最后一个自然日,时间部分为23:59:59:999,返回类型是TDateTime。 | 参数 | 类型 | 说明 | | --------------- | ------- | ------------------------------------------------- | | `a_year` | integer | 整数,年,定义域是[1,9999] | | `aweek_of_year` | integer | 整数,年,表示当年的第几周 | | `aday_of_week` | integer | 整数,表示当周的第几天,默认为7,既一周的最后一天 | 返回:tdatetime ### 示例 范例一: ```tsl year := endOfAWeek(2011, 1, 7); return dateTimeToStr(year); // 输出: 2011-01-09 23:59:59 ``` 范例二: ```tsl year := endOfAWeek (2011, 2, 7); return dateTimeToStr(year); // 输出:2011-01-16 23:59:59 ``` ## `startOfTheDay(a_value)` 声明:function 返回由参数AValue指定的日期的最初时间,也就是将日期设定为当天,将时间部分置0,返回类型是日期 | 参数 | 类型 | 说明 | | --------- | --------- | ----------------------- | | `a_value` | tdatetime | TDateTime类型,日期时间 | 返回:tdatetime ### 示例 ```tsl year := startOfTheDay(strToDateTime('2011-08-08 23:59:59')); return dateTimeToStr(year); // 输出: 2011-08-08 ``` ## `endOfTheDay(a_value)` 声明:function 返回由参数AValue指定的日期的结束时间,也就是将日期设定为当天,时间部分为23:59:59:999,返回类型是日期时间 | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:tdatetime ### 示例 ```tsl year := endOfTheDay(strToDateTime('2011-08-08 01:01:10')); return dateTimeToStr(year); // 输出: 2011-08-08 23:59:59 ``` ## `monthOfTheYear(a_value)` 声明:function 返回由参数AValue指定的月份是当年的第几个月,与MonthOf函数相同。 | 参数 | 类型 | 说明 | | --------- | --------- | ---- | | `a_value` | tdatetime | 日期 | 返回:integer ### 示例 ```tsl month := monthOfTheYear(strToDate('2011-08-08')); return month; // 输出: 8 ``` ## `weekOfTheYear(a_value)` 声明:function 返回由参数AValue指定的时间是处于当年的第几个周,与函数WeekOf相同。返回整数,值域是[1,53] | 参数 | 类型 | 说明 | | --------- | --------- | -------------- | | `a_value` | tdatetime | 日期类型,日期 | 返回:integer ### 示例 ```tsl week := weekOfTheYear(strToDate('2011-01-03')); return week; // 输出: 1 ``` ## `dayOfTheYear(a_value)` 声明:function 返回由参数AValue指定的日期是当年的第几天。 | 参数 | 类型 | 说明 | | --------- | --------- | -------------- | | `a_value` | tdatetime | 日期类型,日期 | 返回:integer ### 示例 ```tsl d := dayOfTheYear(strToDate('2011-01-03')); return d; // 输出: 3 ``` ## `hourOfTheYear(a_value)` 声明:function 返回由参数AValue指定的时间是当年的第几个小时 | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl hour := hourOfTheYear(strToDateTime('2011-01-03 10:00:00')); return hour; // 输出: 58 ``` ## `minuteOfTheYear(a_value)` 声明:function 返回由参数AValue指定的时间是当年的第几分钟 | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl minute := minuteOfTheYear(strToDateTime('2011-01-03 10:00:00')); return minute; // 输出: 3480 ``` ## `secondOfTheYear(a_value)` 声明:function 返回由参数AValue指定的时间是当年的第几秒种 | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl second := secondOfTheYear(strToDateTime('2011-01-03')); return second; // 输出: 208800 ``` ## `milliSecondOfTheYear(a_value)` 声明:function 返回由参数AValue指定的时间是当年的第几毫秒 | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl millisecond := milliSecondOfTheYear(strToDateTime('2011-01-03')); return millisecond; // 输出: 172800000 ``` ## `dayOfTheMonth(a_value)` 声明:function 返回由参数AValue指定的日期是当月的第几天 | 参数 | 类型 | 说明 | | --------- | --------- | -------------- | | `a_value` | tdatetime | 日期类型,日期 | 返回:integer ### 示例 ```tsl day := dayOfTheMonth(strToDateTime('2011-01-22')); return day; // 输出: 22 ``` ## `hourOfTheMonth(a_value)` 声明:function 返回由参数AValue指定的时间是当月的第几小时 | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl hour := hourOfTheMonth(strToDateTime('2011-01-22 10:00:00')); return hour; // 输出: 514 ``` ## `minuteOfTheMonth(a_value)` 声明:function 返回由参数AValue指定的时间是当月的第几分钟 | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl minute := minuteOfTheMonth(strToDateTime('2011-01-22 10:00:00')); return minute; // 输出: 30840 ``` ## `secondOfTheMonth(a_value)` 声明:function 返回由参数AValue指定的时间是当月的第几秒种 | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl second := secondOfTheMonth(strToDateTime('2011-01-22 10:00:00')); return second; // 输出: 1850400 ``` ## `milliSecondOfTheMonth(a_value)` 声明:function 返回由参数AValue指定的时间是当月的第几毫秒 | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl millisecond := milliSecondOfTheMonth(strToDateTime('2011-01-22 10:00:00')); return millisecond; // 输出: 1850400000 ``` ## `dayOfTheWeek(a_value)` 声明:function 返回由参数AValue指定的时间是当周的第几天 | 参数 | 类型 | 说明 | | --------- | --------- | -------------- | | `a_value` | tdatetime | 日期类型,日期 | 返回:integer ### 示例 ```tsl dayofweek := dayOfTheWeek(strToDateTime('2011-01-03')); return dayofweek; // 输出: 1 ``` ## `hourOfTheWeek(a_value)` 声明:function 返回由参数AValue指定的时间是当周的第几小时 | 参数 | 类型 | 说明 | | --------- | --------- | ------------ | | `a_value` | tdatetime | 日期时间类型 | 返回:integer ### 示例 ```tsl hour := hourOfTheWeek(strToDateTime('2011-01-05 10:00:00')); return hour; // 输出: 58 ``` ## `minuteOfTheWeek(a_value)` 声明:function 返回由参数AValue指定的时间是当周的第几分钟 | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl minute := minuteOfTheWeek(strToDateTime('2011-01-05 10:00:00')); return minute; // 输出: 3480 ``` ## `secondOfTheWeek(a_value)` 声明:function 返回由参数AValue指定的时间是当周的第几秒钟 | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl second := secondOfTheWeek(strToDateTime('2011-01-05 10:00:00')); return second; // 输出: 208800 ``` ## `milliSecondOfTheWeek(a_value)` 声明:function 返回由参数AValue指定的时间是当周的第几毫秒 | 参数 | 类型 | 说明 | | --------- | --------- | ------------------ | | `a_value` | tdatetime | 日期时间类型,日期 | 返回:integer ### 示例 ```tsl millisecond := milliSecondOfTheWeek(strToDateTime('2011-01-05 10:00:00')); return millisecond; // 输出: 208800000 ``` ## `hourOfTheDay(a_value)` 声明:function 返回由参数AValue指定的时间是当天的第几小时,返回整数,值域是[1,23] | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl hour := hourOfTheDay(strToDateTime('2011-01-05 23:22:22')); return hour; // 输出: 23 ``` ## `minuteOfTheDay(a_value)` 声明:function 返回由参数AValue指定的时间是当天的第几分钟,起始点是00:00:00 | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl minute := minuteOfTheDay(strToDateTime('2011-01-05 01:22:22')); return minute; // 输出: 82 ``` ## `secondOfTheDay(a_value)` 声明:function 返回由参数AValue指定的时间是当天的第几秒,起始点是00:00:00 | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl second := secondOfTheDay(strToDateTime('2011-01-05 01:30:01')); return second; // 输出: 5401 ``` ## `milliSecondOfTheDay(a_value)` 声明:function 返回由参数AValue指定的时间是当天的第几毫秒,起始点是00:00:00 | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl millisecond := milliSecondOfTheDay(strToDateTime('2011-01-05 01:30:01')); return millisecond; // 输出: 5401000 ``` ## `minuteOfTheHour(a_value)` 声明:function 返回由参数AValue指定的时间是当前小时的第几分钟 | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl minute := minuteOfTheHour(strToDateTime('2011-01-05 01:30:01')); return minute; // 输出: 30 ``` ## `secondOfTheHour(a_value)` 声明:function 返回由参数AValue指定的时间是当前小时的第几秒 | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl second := secondOfTheHour(strToDateTime('2011-01-05 01:30:01')); return second; // 输出: 1801 ``` ## `milliSecondOfTheHour(a_value)` 声明:function 返回由参数AValue指定的时间是当前小时的第几毫秒 | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl millisecond := milliSecondOfTheHour(strToDateTime('2011-01-05 01:30:01')); return millisecond; // 输出: 1801000 ``` ## `secondOfTheMinute(a_value)` 声明:function 返回由参数AValue指定的时间是当前分钟的第几秒 | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl second := secondOfTheMinute(strToDateTime('2011-01-05 01:30:01')); return second; // 输出: 1 ``` ## `milliSecondOfTheMinute(a_value)` 声明:function 返回由参数AValue指定的时间是当前分钟的第几毫秒 | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl millisecond := milliSecondOfTheMinute(strToDateTime('2011-01-05 01:30:01')); return millisecond; // 输出: 1000 ``` ## `milliSecondOfTheSecond(a_value)` 声明:function 返回由参数AValue指定的时间是当前秒钟的第几毫秒 | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl millisecond := milliSecondOfTheSecond(strToDateTime('2011-01-05 01:30:01.990')); return millisecond; // 输出:990 ``` ## `withinPastYears(a_now, athen, a_years)` 声明:function 判断时间ANow和时间AThen的时间间隔是否在Ayears年内。 | 参数 | 类型 | 说明 | | --------- | --------- | -------------------------- | | `a_now` | tdatetime | 日期时间类型,查找时间 | | `athen` | tdatetime | 日期时间类型,查找起始时间 | | `a_years` | integer | 整数,年份 | 返回:bool ### 示例 范例一: ```tsl // 2010年1月5日至2013年1月4日之间,不足3年,因此,判断为2年内 flag := withinPastYears(strToDateTime('2010-01-05'), strToDateTime('2013-01-04'), 2); return flag; // 输出: 1 ``` 范例二: ```tsl // //2010年1月5日至2013年1月5日之间,相隔 3年,因此,判断为不在2年内 flag := withinPastYears(strToDateTime('2010-01-05'), strToDateTime('2013-01-05'), 2); return flag; // 输出: 0 ``` ## `withinPastMonths(a_now, athen, a_months)` 声明:function 判断时间ANow和时间AThen的时间间隔是否在Amonths月内。 | 参数 | 类型 | 说明 | | ---------- | --------- | -------------------------- | | `a_now` | tdatetime | 日期时间类型,查找时间 | | `athen` | tdatetime | 日期时间类型,查找起始时间 | | `a_months` | integer | 整数,月份个数 | 返回:bool ### 示例 范例一: ```tsl // 2011年1月5日到2011年7月6日的天数是182,而天数必须大于182.62(6*30.4375),才能达到6个月,所以,1月5日还属于7月6日前推5个月范围内。 flag := withinPastMonths(strToDateTime('2011-01-05'), strToDateTime('2011-07-06'), 5); return flag; // 输出: 1 ``` 范例二: ```tsl flag := withinPastMonths(strToDateTime('2011-01-05'), strToDateTime('2011-07-07'), 5); return flag; // 输出: 0 ``` ## `withinPastWeeks(a_now, athen, a_weeks)` 声明:function 判断时间ANow和时间AThen的时间间隔是否在AWeeks周内。 | 参数 | 类型 | 说明 | | --------- | --------- | -------------------------- | | `a_now` | tdatetime | 日期时间类型,查找时间 | | `athen` | tdatetime | 日期时间类型,查找起始时间 | | `a_weeks` | integer | 整数,周数 | 返回:bool ### 示例 范例一: ```tsl // 2011年1月1日至2011年1月28日之间的天数为27天,不足28天(4*7),所以仍在3周内 flag := withinPastWeeks(strToDateTime('2011-01-01'), strToDateTime('2011-01-28'), 3); return flag; // 输出: 1 ``` 范例二: ```tsl // 2011年1月1日至2011年1月28日之间的天数为27天,不足28天(4*7),所以仍在3周内 flag := withinPastWeeks(strToDateTime('2011-01-01'), strToDateTime('2011-01-29'), 3); return flag; // 输出: 0 ``` ## `withinPastDays(a_now, athen, a_days)` 声明:function 判断时间ANow和时间AThen的时间间隔是否在ADays自然日内,与系统参数无关。 | 参数 | 类型 | 说明 | | -------- | --------- | -------------------------- | | `a_now` | tdatetime | 日期时间类型,查找时间 | | `athen` | tdatetime | 日期时间类型,查找起始时间 | | `a_days` | integer | 整数,天数 | 返回:bool ### 示例 范例一: ```tsl flag := withinPastDays(strToDate('2011-01-01'), strToDate('2011-01-11'), 10); return flag; // 输出: 1 ``` 范例二: ```tsl flag := withinPastDays(strToDate('2011-01-01'), strToDate('2011-01-12'), 10); return flag; // 输出: 0 ``` ## `withinPastHours(a_now, athen, a_hours)` 声明:function 判断时间ANow和时间AThen的时间间隔是否在AHours个小时内。 | 参数 | 类型 | 说明 | | --------- | --------- | -------------------------- | | `a_now` | tdatetime | 日期时间类型,查找时间 | | `athen` | tdatetime | 日期时间类型,查找起始时间 | | `a_hours` | integer | 整数,小时个数 | 返回:bool ### 示例 范例一: ```tsl // 不足11个小时 flag := withinPastHours(strToDateTime('2011-01-01 00:00:00'), strToDateTime('2011-01-01 10:30:00'), 10); return flag; // 输出: 1 ``` 范例二: ```tsl flag := withinPastHours(strToDateTime('2011-01-01 00:00:00'), strToDateTime('2011-01-01 11:00:00'), 10); return flag; // 输出: 0 ``` ## `withinPastMinutes(a_now, athen, a_minutes)` 声明:function 判断时间ANow和时间AThen的时间间隔是否在AMinutes分钟内。 | 参数 | 类型 | 说明 | | ----------- | --------- | -------------------------- | | `a_now` | tdatetime | 日期时间类型,查找时间 | | `athen` | tdatetime | 日期时间类型,查找起始时间 | | `a_minutes` | integer | 整数,分钟个数 | 返回:bool ### 示例 ```tsl flag := withinPastMinutes(strToDateTime('2011-01-01 10:00:00'), strToDateTime('2011-01-01 10:10:00'), 10); return flag; // 输出: 1 flag := withinPastMinutes(strToDateTime('2011-01-01 10:00:00'), strToDateTime('2011-01-01 10:11:00'), 10); return flag; // 输出: 0 ``` ## `withinPastSeconds(a_now, athen, a_seconds)` 声明:function 判断时间ANow和时间AThen的时间间隔是否在ASeconds秒内。 | 参数 | 类型 | 说明 | | ----------- | --------- | -------------------------- | | `a_now` | tdatetime | 日期时间类型,查找时间 | | `athen` | tdatetime | 日期时间类型,查找起始时间 | | `a_seconds` | integer | 整数,分钟数 | 返回:bool ### 示例 范例一: ```tsl flag := withinPastSeconds(strToDateTime('2011-01-01 10:00:00'), strToDateTime('2011-01-01 10:00:10'), 10); return flag; // 输出: 1 ``` 范例二: ```tsl flag := withinPastSeconds(strToDateTime('2011-01-01 10:00:00'), strToDateTime('2011-01-01 10:00:11'), 10); return flag; // 输出: 0 ``` ## `withinPastMilliSeconds(a_now, athen, a_milli_seconds)` 声明:function 判断时间ANow和时间AThen的时间间隔是否在AMilliSeconds毫秒内。 | 参数 | 类型 | 说明 | | ----------------- | --------- | -------------------------- | | `a_now` | tdatetime | 日期时间类型,查找时间 | | `athen` | tdatetime | 日期时间类型,查找起始时间 | | `a_milli_seconds` | integer | 整数,毫秒数 | 返回:bool ### 示例 ```tsl a_now := strToDateTime('2011-01-01 10:00:00.100'); a_then := strToDateTime('2011-01-01 10:00:00.200'); flag := withinPastMilliSeconds(a_now, a_then , 100); return flag; // 输出: 1 ``` ## `yearsBetween(a_now, athen)` 声明:function 得到参数ANow和参数AThen之间的相距的年数。由于年份不具有相同的长度,例如闰年比非闰年长一天,所以函数的计算是基于一个每年有365.25天的假设进行,并且舍掉了小数尾数。因此我们计算一个非闰年的1月1日到12月31日的结果是0年,而计算一个闰年的1月1日到12月31日的结果是1年。 | 参数 | 类型 | 说明 | | ------- | --------- | ---------------------- | | `a_now` | tdatetime | 日期时间类型,日期时间 | | `athen` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl years := yearsBetween(strToDateTime('2009-01-01 00:00:00'), strToDateTime('2011-01-01 23:59:59.999')); return years; // 输出: 2 ``` ## `monthsBetween(a_now, athen)` 声明:function 得到参数ANow和参数AThen之间的相距的月数。由于月份不具有有相同的长度,所以函数的计算是基于一个每月有30.4375天的假设进行,并且舍掉了小数尾数。因此我们计算从1月1日到1月28日的结果是0,而计算2月1日到3月1日的结果也是0。 | 参数 | 类型 | 说明 | | ------- | --------- | ---------------------- | | `a_now` | tdatetime | 日期时间类型,日期时间 | | `athen` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl months := monthsBetween(strToDateTime('2011-05-01'), strToDateTime('2011-08-01')); return months; // 输出: 3 ``` ## `weeksBetween(a_now, athen)` 声明:function 得到参数ANow和参数AThen之间的相距的周数。周数的计算同样舍掉了小数尾数。例如我们计算从1月1日的12:00 AM到1月6日的Jan 6 at 11:58 PM的结果是0,因为差了1分钟。 | 参数 | 类型 | 说明 | | ------- | --------- | ---------------------- | | `a_now` | tdatetime | 日期时间类型,日期时间 | | `athen` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl weeks := weeksBetween(strToDateTime('2011-05-01'), strToDateTime('2011-08-01')); return weeks; // 输出: 13 ``` ## `daysBetween(a_now, athen)` 声明:function 得到参数ANow和参数AThen之间的相距的天数(自然日)。天数的计算同样舍掉了小数尾数。 | 参数 | 类型 | 说明 | | ------- | --------- | ---------------------- | | `a_now` | tdatetime | 日期时间类型,日期时间 | | `athen` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 范例一: ```tsl days := daysBetween(strToDate('2011-05-01'), strToDate('2011-08-01')); return days; // 输出: 92 ``` 范例二: ```tsl // 不足完整的一天:39815.04167-39814.08333=0.95834 // 2009-01-01 02:00:00:日期时间为39814.08333 // 2009-01-02 01:00:00:日期时间为39815.04167 days := daysBetween(strToDateTime('2009-01-01 02:00:00'), strToDateTime('2009-01-02 01:00:00')); return days; // 输出: 0 ``` ## `hoursBetween(a_now, athen)` 声明:function 得到参数ANow和参数AThen之间的相距的小时数。小时数的计算同样舍掉了小数尾数。 | 参数 | 类型 | 说明 | | ------- | --------- | ---------------------- | | `a_now` | tdatetime | 日期时间类型,日期时间 | | `athen` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl hours := hoursBetween(strToDateTime('2011-08-01 00:00:00'), strToDateTime('2011-08-01 12:00:00')); return hours; // 输出: 12 ``` ## `minutesBetween(a_now, athen)` 声明:function 得到参数ANow和参数AThen之间的相距的分钟数。分钟数的计算同样舍掉了小数尾数。 | 参数 | 类型 | 说明 | | ------- | --------- | ---------------------- | | `a_now` | tdatetime | 日期时间类型,日期时间 | | `athen` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl minutes := minutesBetween(strToDateTime('2011-08-01 00:00:00'), strToDateTime('2011-08-01 12:00:00')); return minutes; // 输出: 720 ``` ## `secondsBetween(a_now, athen)` 声明:function 得到参数ANow和参数AThen之间的相距的秒数。秒数的计算同样舍掉了小数尾数。 | 参数 | 类型 | 说明 | | ------- | --------- | ---------------------- | | `a_now` | tdatetime | 日期时间类型,日期时间 | | `athen` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl seconds := secondsBetween(strToDateTime('2011-08-01 00:00:00'), strToDateTime('2011-08-01 12:00:00')); return seconds; // 输出: 43200 ``` ## `milliSecondsBetween(a_now, athen)` 声明:function 得到参数ANow和参数AThen之间的相距的毫秒数,返回整数 | 参数 | 类型 | 说明 | | ------- | --------- | ---------------------- | | `a_now` | tdatetime | 日期时间类型,日期时间 | | `athen` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl beg_t := strToDateTime('2011-08-01 00:00:00'); end_t := strToDateTime('2011-08-01 12:00:00'); milliseconds := milliSecondsBetween(beg_t, end_t); return milliseconds; // 输出: 43200000 ``` ## `yearSpan(a_now, athen)` 声明:function 得到参数ANow和参数AThen之间的相距的年数。由于年份不具有相同的长度,例如闰年比非闰年长一天,所以函数的计算是基于一个每年有365.25天的假设进行。 | 参数 | 类型 | 说明 | | ------- | --------- | ---------------------- | | `a_now` | tdatetime | 日期时间类型,日期时间 | | `athen` | tdatetime | 日期时间类型,日期时间 | 返回:real ### 示例 ```tsl years := yearSpan(strToDateTime('2010-08-01 00:00:00'), strToDateTime('2012-08-01 12:00:00')); return years; // 输出: 2.00274 ``` ## `monthSpan(a_now, athen)` 声明:function 得到参数ANow和参数AThen之间的相距的月数。由于月份不具有相同的长度,所以函数的计算是基于一个每月有30.4375天的假设进行。 | 参数 | 类型 | 说明 | | ------- | --------- | ---------------------- | | `a_now` | tdatetime | 日期时间类型,日期时间 | | `athen` | tdatetime | 日期时间类型,日期时间 | 返回:real ### 示例 ```tsl months := monthSpan(strToDateTime('2010-08-01 00:00:00'), strToDateTime('2012-08-01 12:00:00')); return months; // 输出: 24.03 ``` ## `weekSpan(a_now, athen)` 声明:function 得到参数ANow和参数AThen之间的相距的周数 | 参数 | 类型 | 说明 | | ------- | --------- | ---------------------- | | `a_now` | tdatetime | 日期时间类型,日期时间 | | `athen` | tdatetime | 日期时间类型,日期时间 | 返回:real ### 示例 ```tsl beg_t := strToDateTime('2010-08-01 00:00:00'); end_t := strToDateTime ('2012-08-01 12:00:00'); weeks := weekSpan(beg_t, end_t); return weeks; // 输出: 104.5 ``` ## `daySpan(a_now, athen)` 声明:function 得到参数ANow和参数AThen之间的相距的天数。 | 参数 | 类型 | 说明 | | ------- | --------- | ---------------------- | | `a_now` | tdatetime | 日期时间类型,日期时间 | | `athen` | tdatetime | 日期时间类型,日期时间 | 返回:real ### 示例 ```tsl beg_t := strToDateTime('2010-08-01 00:00:00'); end_t := strToDateTime('2012-08-01 12:00:00'); days := daySpan(beg_t, end_t); return days; // 输出: 731.5 ``` ## `hourSpan(a_now, athen)` 声明:function 得到参数ANow和参数AThen之间的相距的小时数 | 参数 | 类型 | 说明 | | ------- | --------- | ---------------------- | | `a_now` | tdatetime | 日期时间类型,日期时间 | | `athen` | tdatetime | 日期时间类型,日期时间 | 返回:real ### 示例 ```tsl hours := hourSpan(strToDateTime('2010-08-01 00:00:00'), strToDateTime('2012-08-01 12:00:00')); return hours; // 输出: 17556 ``` ## `minuteSpan(a_now, athen)` 声明:function 得到参数ANow和参数AThen之间的相距的分钟数 | 参数 | 类型 | 说明 | | ------- | --------- | ---------------------- | | `a_now` | tdatetime | 日期时间类型,日期时间 | | `athen` | tdatetime | 日期时间类型,日期时间 | 返回:real ### 示例 ```tsl beg_t := strToDateTime('2010-08-01 00:00:00'); end_t := strToDateTime('2012-08-01 12:00:00'); minutes := minuteSpan(beg_t, end_t); return minutes; // 输出: 1053360 ``` ## `secondSpan(a_now, athen)` 声明:function 得到参数ANow和参数AThen之间的相距的秒数 | 参数 | 类型 | 说明 | | ------- | --------- | ---------------------- | | `a_now` | tdatetime | 日期时间类型,日期时间 | | `athen` | tdatetime | 日期时间类型,日期时间 | 返回:real ### 示例 ```tsl beg_t := strToDateTime('2010-08-01 00:00:00'); end_t := strToDateTime('2012-08-01 12:00:00'); seconds := secondSpan(beg_t, end_t); return seconds; // 输出: 63201600 ``` ## `incYear(a_value, a_number_of_years)` 声明:function 得到自参数AValue指定的时间向后推移AnumberOfYears年的时间,参数AnumberOfYears也可以为负值,表示向前推移。 | 参数 | 类型 | 说明 | | ------------------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | | `a_number_of_years` | integer | 整数,表示年数 | 返回:tdatetime ### 示例 ```tsl incyears := incYear(strToDateTime('2010-08-01'), 10); return dateToStr(incyears); // 输出: 2020-08-01 ``` ## `incMonth(date_time, number_of_months)` 声明:function 返回参数指定的时间DateTime之后NumberOfMonths个月的时间。参数NumberOfMonths也可以为负值,表示向前推移 | 参数 | 类型 | 说明 | | ------------------ | --------- | ---------------------- | | `date_time` | tdatetime | 日期时间类型,日期时间 | | `number_of_months` | integer | 整数,月数 | 返回:tdatetime ### 示例 ```tsl incmonths := incMonth(strToDateTime('2010-08-01'), 2); return dateToStr(incmonths); // 输出: 2010-10-01 ``` ## `incWeek(a_value, a_number_of_weeks)` 声明:function 得到自参数AValue指定的时间向后推移AnumberOfWeeks周的时间,参数AnumberOfWeeks也可以为负值,表示向前推移。 | 参数 | 类型 | 说明 | | ------------------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | | `a_number_of_weeks` | integer | 整数,表示周数 | 返回:tdatetime ### 示例 ```tsl incweeks := incWeek(strToDateTime('2010-08-01'), 1); return dateToStr(incweeks); // 输出: 2010-08-08 ``` ## `incDay(a_value, a_number_of_days)` 声明:function 得到自参数AValue指定的时间向后推移AnumberOfDays天的时间(自然日),参数AnumberOfDays也可以为负值,表示向前推移。 | 参数 | 类型 | 说明 | | ------------------ | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | | `a_number_of_days` | integer | 整数,表示天数 | 返回:tdatetime ### 示例 ```tsl incdays := incDay(strToDateTime('2010-08-01'), 10); return dateToStr(incdays); // 输出: 2010-08-11 ``` ## `incHour(a_value, a_number_of_hours)` 声明:function 得到自参数AValue指定的时间向后推移AnumberOfHours小时的时间,参数也可以为负值,表示向前推移。 | 参数 | 类型 | 说明 | | ------------------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | | `a_number_of_hours` | integer | 整数,表示小时数 | 返回:tdatetime ### 示例 ```tsl inchours := incHour(strToDateTime('2010-08-01 00:01:01'), 10); return dateTimeToStr(inchours); // 输出: 2010-08-01 10:01:01 ``` ## `incMinute(a_value, a_number_of_minutes)` 声明:function 得到自参数AValue指定的时间向后推移AnumberOfMinutes分钟的时间,参数ANumberOfMinutes也可以为负值,表示向前推移。 | 参数 | 类型 | 说明 | | --------------------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | | `a_number_of_minutes` | integer | 整数,表示分钟数 | 返回:tdatetime ### 示例 ```tsl incminutes := incMinute(strToDateTime('2010-08-01 00:01:01'), 50); return dateTimeToStr(incminutes); // 输出: 2010-08-01 00:51:01 ``` ## `incSecond(a_value, a_number_of_seconds)` 声明:function 得到自参数AValue指定的时间向后推移AnumberOfSeconds秒的时间,参数AnumberOfSecond也可以为负值,表示向前推移。 | 参数 | 类型 | 说明 | | --------------------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | | `a_number_of_seconds` | integer | 整数,表示秒数 | 返回:tdatetime ### 示例 ```tsl incseconds := incSecond(strToDateTime('2010-08-01 00:01:01'), 50); return dateTimeToStr(incseconds); // 输出: 2010-08-01 00:01:51 ``` ## `incMilliSecond(a_value, a_number_of_milli_seconds)` 声明:function 得到自参数AValue指定的时间向后推移AnumberOfMilliSeconds毫秒的时间,参数AnumberOfMilliSeconds也可以为负值,表示向前推移。 | 参数 | 类型 | 说明 | | --------------------------- | --------- | ----------------------- | | `a_value` | tdatetime | TDateTime类型,日期时间 | | `a_number_of_milli_seconds` | integer | 整数,表示毫秒数 | 返回:tdatetime ### 示例 ```tsl incmilliseconds := incMilliSecond(strToDateTime('2010-08-01 00:01:01.950'), 50); return dateTimeToStr(incmilliseconds); // 输出: 2010-08-01 00:01:02 ``` ## `encodeDateTime(a_year, a_month, a_day, a_hour, aminute, asecond, amilli_second)` 声明:function 根据给定的参数AYear, AMonth, ADay, AHour, AMinute, ASecond, AmilliSecond分别作为年、月、日、小时、分钟、秒、毫秒组成一个日期时间型数据返回 | 参数 | 类型 | 说明 | | --------------- | ------- | ---------------------------------------------------------------------- | | `a_year` | integer | 整数,年,年,定义域[1,9999] | | `a_month` | integer | 整数,月,月,定义域[1,12] | | `a_day` | integer | 整数,日,日期,定义域[1,31] | | `a_hour` | integer | 整数,小时,小时,定义域[0,24],如果是24,则要求分钟、秒、毫秒全部为0 | | `aminute` | integer | 整数,分钟,定义域[0,59] | | `asecond` | integer | 整数,秒,定义域[0,59] | | `amilli_second` | integer | 整数,毫秒,定义域[0,999] | 返回:tdatetime ### 示例 ```tsl timeset := encodeDateTime(2011, 08, 08, 09, 32, 45, 990); return dateTimeToStr(timeset); // 输出: 2011-08-08 09:32:45 ``` ## `decodeDateTime(a_value, a_year, a_month, a_day, a_hour, aminute, asecond, amilli_second)` 声明:function 过程,将给定TDateTime类型的参数AValue分解为年、月、日、小时、分钟、秒、毫秒分别存到参数AYear, AMonth, ADay, AHour, AMinute, ASecond, AmilliSecond中。 | 参数 | 类型 | 说明 | | --------------- | --------- | ---------------------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | | `a_year` | integer | 整数,年,定义域[1,9999],返回值 | | `a_month` | integer | 整数,月,定义域[1,12],返回值 | | `a_day` | integer | 整数,日,定义域[1,31],返回值 | | `a_hour` | integer | 整数,小时,定义域[0,24],返回值 | | `aminute` | integer | 整数,分钟,定义域[0,59],返回值 | | `asecond` | integer | 整数,秒,定义域[0,59],返回值 | | `amilli_second` | integer | 整数,毫秒,定义域[0,999],返回值 | 返回:integer ### 示例 ```tsl end_t := strToDateTime('2011-08-08 12:09:10.990'); decodeDateTime(end_t, year, month, day, hour, minute, second, millisecond); return array(year, month, day, hour, minute, second, millisecond); // 输出:array(2011,8,8,12,9,10,990) ``` ## `encodeDateWeek(a_year, aweek_of_year, aday_of_week)` 声明:function 根据给定的参数AValue年份,以及给定在此年份的第AWeekOfYear周,以及给定的此周的第ADayOfWeek天来确定的,时间部分置0。 | 参数 | 类型 | 说明 | | --------------- | ------- | ------------------------------------------------ | | `a_year` | integer | 整数,年,定义域[1,9999] | | `aweek_of_year` | integer | 整数,周,定义域[1,53] | | `aday_of_week` | integer | 整数,定义域[1,7],并小于当周属于当年的最大天数 | 返回:tdatetime ### 示例 ```tsl // 一个自然周至少要有4天属于该年的日期,这一周才属于这年。 // 1月1日和1月2日所属周只有2天处于2011年,所以,这周属于2010年,2011年的第一周从2011年1月3日算起 week := encodeDateWeek(2011, 1, 1); return dateToStr(week); // 输出: 2011-01-03 ``` ## `decodeDateWeek(a_value, a_year, aweek_of_year, aday_of_week)` 声明:function 过程,根据一个TDateTime类型的时间,分别分解为年份,周数(属于当年第几周),天数(当周的第几天),并分别存在参数AYear, AWeekOfYear, AdayOfWeek中。 | 参数 | 类型 | 说明 | | --------------- | --------- | ------------------------------ | | `a_value` | tdatetime | 日期时间类型,日期时间 | | `a_year` | integer | 整数,年,返回值 | | `aweek_of_year` | integer | 整数,月,返回值 | | `aday_of_week` | integer | 整数,表示当周的第几天,返回值 | 返回:integer ### 示例 ```tsl decodeDateWeek(strToDateTime('2011-08-08'), year, weekofyear, dayofweek); return array( year, weekofyear, dayofweek); // 输出: array(2011, 32,1) ``` ## `decodeDateDay(a_value, a_year, a_day_of_year)` 声明:function 过程,根据参数AValue的时间确定所属的年份以及在当年第多少天,并把分别存到参数AYear, AdayOfYear中 | 参数 | 类型 | 说明 | | --------------- | --------- | ------------------ | | `a_value` | tdatetime | 日期时间类型 | | `a_year` | integer | 整数,年份,返回值 | | `a_day_of_year` | integer | 整数,天数,返回值 | 返回:integer ### 示例 ```tsl decodeDateDay(strToDateTime('2011-08-08'), year, dayofyear); return array(year, dayofyear); // 输出: array(2011,220) ``` ## `encodeDateMonthWeek(a_year, a_month, aweek_of_month, aday_of_week)` 声明:function 根据给定参数AYear, AMonth分别作为年、月,AWeekOfMonth作为当月的第几周,AdayOfWeek作为当周的第几天组成一个日期类型值返回,时间部分置0,组成日期返回。 | 参数 | 类型 | 说明 | | ---------------- | ------- | ------------------------- | | `a_year` | integer | 整数,年,定义域[1,9999] | | `a_month` | integer | 整数,月,定义域[1,12] | | `aweek_of_month` | integer | 整数,当月的第几周 | | `aday_of_week` | integer | 整数,当周的第几天 | 返回:tdatetime ### 示例 ```tsl monthweek := encodeDateMonthWeek(2011, 8, 2, 1); return dateTimeToStr(monthweek); // 输出: 2011-08-08 ``` ## `decodeDateMonthWeek(a_value, a_year, a_month, aweek_of_month, aday_of_week)` 声明:function 根据给定的参数根据参数AValue的时间确定所属的年份、月份以及当月第多少周,当周第多少天,并把分别存到参数Ayear、Amonth、AweekOfMonth、ADayOfWeek中。 | 参数 | 类型 | 说明 | | ---------------- | --------- | --------------------------------- | | `a_value` | tdatetime | 日期类型,分解的日期 | | `a_year` | integer | 整数,年,定义域[1,9999],返回值 | | `a_month` | integer | 整数,月,定义域[1,12],返回值 | | `aweek_of_month` | integer | 整数,当月的第几周,返回值 | | `aday_of_week` | integer | 整数,当周的第几天,返回值 | 返回:integer ### 示例 ```tsl decodeDateMonthWeek(strToDateTime("2011-08-10"), year, month, weekof_month, day_of_week1); return array(year, month, weekof_month, day_of_week1); // 输出: array(2011,8,2,3) ``` ## `tryEncodeDateTime(a_year, a_month, a_day, a_hour, aminute, asecond, amilli_second, a_value)` 声明:function 根据给定的参数AYear, AMonth, ADay, AHour, AMinute, ASecond, AmilliSecond分别作为年、月、日、小时、分钟、秒、毫秒组成一个日期时间型变量存到参数AValue中,并返回一个布尔型真假值,表示是否是个有效的日期 | 参数 | 类型 | 说明 | | --------------- | --------- | ---------------------------------------------------------------- | | `a_year` | integer | 整数,年,定义域[1,9999] | | `a_month` | integer | 整数,月,定义域[1,12] | | `a_day` | integer | 整数,日,定义域[1,31] | | `a_hour` | integer | 整数,小时,定义域[0,24],如果是24,则要求分钟、秒、毫秒全部为0 | | `aminute` | integer | 整数,分钟,定义域[0,59] | | `asecond` | integer | 整数,秒,定义域[0,59] | | `amilli_second` | integer | 整数,毫秒,定义域[0,999] | | `a_value` | tdatetime | 日期时间类型,组成的日期,返回值 | 返回:bool ### 示例 ```tsl flag := tryEncodeDateTime(2011, 8, 10, 10, 01, 01, 999, atime); return array(flag, dateTimeToStr(atime)); // 输出: array(1,'2011-08-10 10:01:01') ``` ## `tryEncodeDateWeek(a_year, a_week_of_year, a_value, aday_of_week)` 声明:function 根据给定的参数AYear年份、此年份的第AWeekOfYear周,以及给定的此周的第ADayOfWeek天来确定的一个日期类型的值存到参数AValue中,时间部分置0。返回布尔值,表示是否是个有效的日期 | 参数 | 类型 | 说明 | | ---------------- | --------- | ------------------------------------------------ | | `a_year` | integer | 整数,年,定义域[1,9999] | | `a_week_of_year` | integer | 整数,周数,定义域[1,53] | | `a_value` | tdatetime | 日期类型,返回值 | | `aday_of_week` | integer | 整数,定义域[1,7],并小于当周属于当年的最大天数 | 返回:bool ### 示例 ```tsl flag := tryEncodeDateWeek(2011, 1, atime, 1); return array(flag, dateTimeToStr(atime)); // 输出: array(1,'2011-01-03') ``` ## `tryEncodeDateDay(a_year, a_day_of_year, a_value)` 声明:function 过程,根据给定的参数AYear年份、以及指定在给定年份的第ADayofYear天来生成一个日期并存到参数AValue中,时间部分置0。 | 参数 | 类型 | 说明 | | --------------- | --------- | ------------------ | | `a_year` | integer | 整数,年份, | | `a_day_of_year` | integer | 整数,当年的第几天 | | `a_value` | tdatetime | 日期类型,返回值 | 返回:bool ### 示例 ```tsl flag := tryEncodeDateDay(2011, 1, atime); return array(flag, dateTimeToStr(atime)); // 输出: array(1,'2011-01-01') ``` ## `tryEncodeDateMonthWeek(a_year, a_month, aweek_of_month, aday_of_week, a_value)` 声明:function 根据参数指定的年份AYear、月份Amonth、以及当月的第几周数AweekOfMonth和当周的第几天ADayOfWeek确定出一个日期型值存到参数AValue中。函数返回一个布尔型真假值,以表明日期是否有效转化 | 参数 | 类型 | 说明 | | ---------------- | --------- | ------------------------- | | `a_year` | integer | 整数,年,定义域[1,9999] | | `a_month` | integer | 整数,月,定义域[1,12] | | `aweek_of_month` | integer | 整数,当月的第几周 | | `aday_of_week` | integer | 整数,当周的第几天 | | `a_value` | tdatetime | 日期类型,组成的日期 | 返回:bool ### 示例 ```tsl flag := tryEncodeDateMonthWeek(2011, 1, 1, 1, atime); return array(flag, dateTimeToStr(atime)); // 输出: array(1.0,'2011-01-03') ``` ## `recodeYear(a_value, a_year)` 声明:function 将参数Ayear指定的年份替换掉参数 AValue中的相应的年份信息,得到的日期类型返回 | 参数 | 类型 | 说明 | | --------- | --------- | -------------- | | `a_value` | tdatetime | 日期类型,日期 | | `a_year` | integer | 整数,年份 | 返回:tdatetime ### 示例 范例一: ```tsl new_time := recodeYear(strToDateTime("2010-08-01"), 2009); return dateTimeToStr(new_time); // 输出: 2009-08-01 ``` 范例二: ```tsl // 用try...except...end语句进行异常处理,如果无法替换成有效的日期,则把NewTime设置为0. try new_time := recodeYear(strToDateTime("2012-02-29"), 2013); except new_time := 0; end; return new_time; // 输出: 0 ``` ## `recodeMonth(a_value, a_month)` 声明:function 将参数AMonth指定的月份替换掉参数 AValue中的相应的月份信息,得到的TDateTime类型返回。 | 参数 | 类型 | 说明 | | --------- | --------- | -------------- | | `a_value` | tdatetime | 日期类型,日期 | | `a_month` | integer | 整数,月份 | 返回:tdatetime ### 示例 范例一: ```tsl try new_time := recodeMonth(strToDateTime("2011-08-10"), 10); new_time := dateTimeToStr(new_time); except new_time := 0; end; return new_time; // 输出: 2011-10-10 ``` 范例二: ```tsl try new_time := recodeMonth(strToDateTime("2013-3-31"), 4); new_time := dateTimeToStr(new_time); except new_time := 0; end; return new_time; // 输出: 0 ``` ## `recodeDay(a_value, a_day)` 声明:function 将参数ADay指定的日期(1至31)替换掉参数AValue中的相应的日期信息,得到的日期类型返回。 | 参数 | 类型 | 说明 | | --------- | --------- | ------------------------- | | `a_value` | tdatetime | 日期类型,日期 | | `a_day` | integer | 整数,日期,定义域[1,31] | 返回:tdatetime ### 示例 范例一: ```tsl try new_time := recodeDay(strToDateTime("2011-08-10"), 1); new_time := dateToStr(new_time); except new_time := 0; end; return new_time; // 输出: 2011-08-01 ``` 范例二: ```tsl try new_time := recodeDay(strToDateTime("2011-02-28"), 31); new_time := dateToStr(new_time); except new_time := 0; end; return new_time; // 输出: 1899-12-30(设置的天超过当月天数时返回零日期,不抛异常) ``` ## `recodeHour(a_value, a_hour)` 声明:function 将参数AHour指定的小时(0至24)替换掉参数AValue中的相应的日期信息,得到的日期时间返回。 | 参数 | 类型 | 说明 | | --------- | --------- | ------------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | | `a_hour` | integer | 整数,小时,定义域[0,24] | 返回:tdatetime ### 示例 ```tsl new_time := recodeHour(strToDateTime("2011-08-10 12:12:12"), 1); return dateTimeToStr(new_time); // 输出: 2011-08-10 01:12:12 ``` ## `recodeMinute(a_value, a_minute)` 声明:function 将参数AMinute指定的分钟(0至59)替换掉参数AValue中的相应的分钟信息,得到的日期时间类型返回 | 参数 | 类型 | 说明 | | ---------- | --------- | ------------------------- | | `a_value` | tdatetime | 日期时间类型 | | `a_minute` | integer | 整数,分钟,定义域[0,59] | 返回:tdatetime ### 示例 ```tsl new_time := recodeMinute (strToDateTime("2011-08-10 12:12:12"), 9); return dateTimeToStr(new_time); // 输出: 2011-08-10 12:09:12 ``` ## `recodeMilliSecond(a_value, a_milli_second)` 声明:function 将参数ASecond指定的毫秒数(0至999)替换掉参数AValue中的相应的毫秒数信息,得到的日期时间类型返回 | 参数 | 类型 | 说明 | | ---------------- | --------- | ---------------------------- | | `a_value` | tdatetime | :日期时间类型 | | `a_milli_second` | integer | 整数,毫秒数,定义域[0,999] | 返回:tdatetime ### 示例 ```tsl new_time := recodeMilliSecond(strToDateTime("2011-08-10 12:12:12.999"), 100); return milliSecondOf (new_time); // 输出: 100 ``` ## `recodeDate(a_value, a_year, a_month, a_day)` 声明:function 将参数Ayear、Amonth、Aday分别指定年份、月份、日期替换掉参数AValue中的相应的年份、月份、日期信息,保留时间信息,得到的日期时间类型返回 | 参数 | 类型 | 说明 | | --------- | --------- | -------------------------------------------------------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | | `a_year` | integer | 整数,年份,定义域[0,9999] | | `a_month` | integer | 整数,月份,定义域[0,12] | | `a_day` | integer | 整数,日期,定义域[0,31],并且要使Ayear、Amonth、Aday组成的时间有效 | 返回:tdatetime ### 示例 ```tsl new_time := recodeDate(strToDateTime("2011-08-10 12:12:12"), 2010, 8, 9); return dateTimeToStr(new_time); // 输出: 2010-08-09 12:12:12 ``` ## `recodeTime(a_value, a_hour, a_minute, a_second, amilli_second)` 声明:function 将参数Ayear、Amonth、Aday、AHour、AMinute、Asecond、AMilliSecond分别指定小时、分钟、秒钟、毫秒替换掉参数AValue中的相应的小时、分钟、秒钟、毫秒信息,保留日期信息,得到的日期时间类型返回 | 参数 | 类型 | 说明 | | --------------- | --------- | -------------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | | `a_hour` | integer | 整数,小时,定义域[0,24] | | `a_minute` | integer | 整数,分钟,定义域[0,59] | | `a_second` | integer | 整数,秒钟,定义域[0,59] | | `amilli_second` | integer | 整数,毫秒,定义域[0,999] | 返回:tdatetime ### 示例 ```tsl new_time := recodeTime(strToDateTime("2011-08-10 12:12:12.999"), 10, 8, 9, 100); return dateTimeToStr(new_time); // 输出: 2011-08-10 10:08:09 ``` ## `recodeDateTime(a_value, a_year, a_month, a_day, a_hour, a_minute, a_second, amilli_second)` 声明:function 将参数Ayear、Amonth、Aday、AHour、AMinute、Asecond、AMilliSecond分别指定年份、月份、日期、小时、分钟、秒钟、毫秒替换掉参数AValue中的相应的年份、月份、日期、小时、分钟、秒钟、毫秒信息。对于不改变的变量,可以设置为65535(最大的WORD类型值),来告诉函数此参数对应的响应时间部分不需替换。函数得到的TDateTime类型返回 | 参数 | 类型 | 说明 | | --------------- | --------- | -------------------------------------------------------------------- | | `a_value` | tdatetime | 日期时间类型,被替换的日期时间 | | `a_year` | integer | 整数,年份,定义域[0,9999] | | `a_month` | integer | 整数,月份,定义域[0,12] | | `a_day` | integer | 整数,日期,定义域[0,12],并且要使Ayear、Amonth、Aday组成的时间有效 | | `a_hour` | integer | 整数,小时,定义域[0,24] | | `a_minute` | integer | 整数,分钟,定义域[0,59] | | `a_second` | integer | 整数,秒钟,定义域[0,59] | | `amilli_second` | integer | 整数,毫秒,定义域[0,999] | 返回:tdatetime ### 示例 ```tsl new_time := recodeDateTime(strToDateTime("2011-08-10 12:12:12.999"), 2010, 8, 10, 10, 8, 9, 100); return dateTimeToStr(new_time); // 输出: 2010-08-10 10:08:09 ``` ## `tryRecodeDateTime(a_value, a_year, a_month, a_day, a_hour, a_minute, a_second, amilli_second, aresult)` 声明:function 本函数同RecodeDateTime函数非常类似。将参数Ayear、Amonth、Aday、 AHour、AMinute、Asecond、AMilliSecond分别指定年份、月份、日期、小时、分钟、秒钟、毫秒替换掉参数AValue中的相应的年份、月份、日期、小时、分钟、秒钟、毫秒信息,并将新的TDateTime类型时间存到参数Aresult中。对于不需改变的变量,可以设置为65535(最大的WORD类型值),来告诉函数此参数对应的响应时间部分不需替换 | 参数 | 类型 | 说明 | | --------------- | --------- | -------------------------------------------------------------------- | | `a_value` | tdatetime | 日期时间类型,被替换的日期时间 | | `a_year` | integer | 整数,年份,定义域[0,9999] | | `a_month` | integer | 整数,月份,定义域[0,12] | | `a_day` | integer | 整数,日期,定义域[0,12],并且要使Ayear、Amonth、Aday组成的时间有效 | | `a_hour` | integer | 整数,小时,定义域[0,24] | | `a_minute` | integer | 整数,分钟,定义域[0,59] | | `a_second` | integer | 整数,秒钟,定义域[0,59] | | `amilli_second` | integer | 整数,毫秒,定义域[0,999] | | `aresult` | tdatetime | 日期时间类型,替换后的日期时间 | 返回:bool ### 示例 ```tsl tryRecodeDateTime(strToDateTime("2011-08-10 12:12:12.999"), 2010, 8, 10, 10, 8, 9, 100, aresult); return dateTimeToStr(aresult); // 输出: 2010-08-10 10:08:09 ``` ## `compareDateTime(a, b)` 声明:function 比较时间A和时间B的大小,返回它们的关系 | 参数 | 类型 | 说明 | | ---- | --------- | ---------------------- | | `a` | tdatetime | 日期时间类型,日期时间 | | `b` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl result := compareDateTime(strToDateTime("2011-08-10"), strToDateTime("2011-08-11")); return result; // 输出: -1 ``` ## `sameDateTime(a, b)` 声明:function 判断时间A和时间B是否相等。 | 参数 | 类型 | 说明 | | ---- | --------- | ---------------------- | | `a` | tdatetime | 日期时间类型,日期时间 | | `b` | tdatetime | 日期时间类型,日期时间 | 返回:bool ### 示例 ```tsl flag := sameDateTime(strToDateTime("2011-08-10"), strToDateTime("2011-08-11")); return flag; // 输出: 0 ``` ## `compareDate(a, b)` 声明:function 比较时间A所属的日期和时间B所属的日期的大小,返回它们的关系 | 参数 | 类型 | 说明 | | ---- | --------- | ---------------------- | | `a` | tdatetime | 日期时间类型,日期时间 | | `b` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl result := compareDate(strToDateTime("2011-08-10"), strToDateTime("2011-08-11")); return result; // 输出: -1 ``` ## `sameDate(a, b)` 声明:function 返回布尔型真假值,判断时间A所属的日期和时间B所属的日期是否是同一天,如果是同一天,返回真,否则返回假。 | 参数 | 类型 | 说明 | | ---- | --------- | ---------------------- | | `a` | tdatetime | 日期时间类型,日期时间 | | `b` | tdatetime | 日期时间类型,日期时间 | 返回:bool ### 示例 ```tsl flag := sameDate(strToDateTime("2011-08-10 01:00:00"), strToDateTime("2011-08-10 02:00:00")); return flag; // 输出: 1 ``` ## `compareTime(a, b)` 声明:function 比较A和B的时间部分(不考虑日期部分),返回它们的关系 | 参数 | 类型 | 说明 | | ---- | --------- | ---------------------- | | `a` | tdatetime | 日期时间类型,日期时间 | | `b` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl result := compareTime(strToDateTime("2011-08-10 01:00:00"), strToDateTime("2011-08-11 01:00:00")); return result; // 输出: 0 ``` ## `sameTime(a, b)` 声明:function 判断A和B的时间部分是否相等(不考虑日期部分),如果相等,返回真,否则返回假。 | 参数 | 类型 | 说明 | | ---- | --------- | ---------------------- | | `a` | tdatetime | 日期时间类型,日期时间 | | `b` | tdatetime | 日期时间类型,日期时间 | 返回:bool ### 示例 ```tsl result := sameTime(strToDateTime("2011-08-10 01:00:00"), strToDateTime("2011-08-11 01:00:00")); return result; // 输出: 1 ``` ## `nthDayOfWeek(a_value)` 声明:function 返回参数AValue指定的日期在当月是第几周,注意,这里的周是代表7天,就是第几个7天。因此,每月的1至7日返回1,8至14日返回2,15至21日返回3,以此类推。 | 参数 | 类型 | 说明 | | --------- | --------- | ---------------------- | | `a_value` | tdatetime | 日期时间类型,日期时间 | 返回:integer ### 示例 ```tsl end_t := strToDateTime("2014-01-06"); week_num := nthDayOfWeek(end_t); wofm := weekOfTheMonth(end_t); return array(week_num, wofm); // 输出: array(1,2) ``` ## `decodeDayOfWeekInMonth(a_value, a_year, a_month, anth_day_of_week, aday_of_week)` 声明:function 过程,根据参数AValue指定的日期得到年份Ayear、月份AMonth、周数AnthDayOfWeek、当周天数AdayOfWeek | 参数 | 类型 | 说明 | | ------------------ | --------- | ---------------- | | `a_value` | tdatetime | 日期时间类型 | | `a_year` | integer | 整数,年,年份 | | `a_month` | integer | 整数,月,月份 | | `anth_day_of_week` | integer | 整数,周数 | | `aday_of_week` | integer | 整数,当周第几天 | 返回:integer ### 示例 ```tsl end_t := strToDateTime("2011-08-10 12:10:09"); decodeDayOfWeekInMonth(endt, ayear, amonth, a_nth_day_of_week, a_day_of_week); return array(ayear, amonth, a_nth_day_of_week, a_day_of_week ); // 输出: array(2011,8,2,3) ``` ## `encodeDayOfWeekInMonth(a_year, a_month, anth_day_of_week, aday_of_week)` 声明:function 根据参数指定的年份Ayear、月份AMonth、周数AnthDayOfWeek、当周天数AdayOfWeek得到一个TDateTime类型值,时间部分置0 | 参数 | 类型 | 说明 | | ------------------ | ------- | --------------------------- | | `a_year` | integer | 整数,年份,定义域[0,9999] | | `a_month` | integer | 整数,月份,定义域[0,12] | | `anth_day_of_week` | integer | 整数,周数 | | `aday_of_week` | integer | 整数,当周第几天 | 返回:tdatetime ### 示例 ```tsl // 2013年10月1日是周二,1日至6日不属于这个月的周,从7日(周一)所属周开始算起 return encodeDayOfWeekInMonth(2013, 10, 2, 1); // 输出41561('2013-10-14') ``` ## `tryEncodeDayOfWeekInMonth(a_year, a_month, anth_day_of_week, aday_of_week, a_value)` 声明:function 跟EncodeDayOfWeekInMonth函数非常类似。根据参数指定的年份Ayear、月份AMonth、周数AnthDayOfWeek、当周天数AdayOfWeek得到一个TDateTime类型值,存到参数AValue中,时间部分置0。函数返回一个真假值,如果给定的参数能够得到合法的日期就返回真,否则返回假 | 参数 | 类型 | 说明 | | ------------------ | --------- | ---------------------------- | | `a_year` | integer | 整数,年份,定义域[0,9999] | | `a_month` | integer | 整数,月份,定义域[0,12] | | `anth_day_of_week` | integer | 整数,周数 | | `aday_of_week` | integer | 整数,当周第几天 | | `a_value` | tdatetime | 日期类型,组成的日期,返回值 | 返回:bool ### 示例 ```tsl tryEncodeDayOfWeekInMonth(2013, 10, 2, 1, newtime); return dateTimeToStr(newtime); // 输出: 2013-10-14 ``` ## `dateTimeToJulianDate(a_value)` 声明:function 将TDateTime类型的参数转换成儒略日类型。儒略日类型类型是自从格林威治公元前4713年1月一日中午到计时点的天数,包括小数。这种时间用在天文学,地球物理学等需要精确时间的地方 | 参数 | 类型 | 说明 | | --------- | --------- | ------------- | | `a_value` | tdatetime | TDateTime类型 | 返回:real ### 示例 ```tsl return dateTimeToJulianDate(strToDateTime('2014-01-01 10:00:00')); // 输出2456658.91667 ``` ## `julianDateToDateTime(a_value)` 声明:function 将儒略日类型的时间转换成TDateTime类型的时间。儒略日类型类型是自从格林威治公元前4713年1月一日中午到计时点的天数,包括小数。这种时间用在天文学,地球物理学等需要精确时间的地方 | 参数 | 类型 | 说明 | | --------- | ---- | -------------------------- | | `a_value` | real | 实数,代表儒略日类型的时间 | 返回:tdatetime ### 示例 ```tsl a := julianDateToDateTime(2456658.91667); return dateTimeToStr(a); // 输出2014-01-01 10:00:00 ``` ## `tryJulianDateToDateTime(a_value, a_date_time)` 声明:function 将儒略日类型的时间转换成TDateTime类型的时间并存到参数AdateTime中。函数返回布尔型真假值,表示是否可以转换成功 | 参数 | 类型 | 说明 | | ------------- | --------- | ---------------------------------------- | | `a_value` | real | 实数,代表儒略日类型的时间 | | `a_date_time` | tdatetime | 日期时间类型,转化成功的日期时间,返回值 | 返回:bool ### 示例 ```tsl flag := tryJulianDateToDateTime(2456658.91667, t); if flag then return dateTimeToStr(t); else return 0; // 输出2014-01-01 10:00:00 ``` ## `dateTimeToModifiedJulianDate(a_value)` 声明:function 将TDateTime类型的参数转换成新儒略日类型。新儒略日类型类型是在儒略日类型上改进的,计时发法是自从格林威治1958年11月17日午夜到计时点的天数,包括小数 | 参数 | 类型 | 说明 | | --------- | --------- | ------------ | | `a_value` | tdatetime | 日期时间类型 | 返回:real ### 示例 ```tsl a := dateTimeToModifiedJulianDate(strToDateTime('2014-01-01 10:00:00')); return a; // 输出56658.41667 ``` ## `modifiedJulianDateToDateTime(a_value)` 声明:function 将新儒略日类型的参数AValue转换成TDateTime类型的。新儒略日类型类型是在儒略日类型上改进的,计时发法是自从格林威治1958年11月17日午夜到计时点的天数,包括小数 | 参数 | 类型 | 说明 | | --------- | ---- | ---------------------------- | | `a_value` | real | 实数,表示新儒略日类型的时间 | 返回:tdatetime ### 示例 ```tsl t := modifiedJulianDateToDateTime(56658.41667); return dateTimeToStr(t); // 输出2014-01-01 10:00:00 ``` ## `tryModifiedJulianDateToDateTime(a_value, a_date_time)` 声明:function 与ModifiedJulianDateToDateTime函数非常类似,将新儒略日类型的参数AValue转换成TDateTime类型的值存到参数AdateTime中。函数返回布尔型真假值,表示是否转换成功 | 参数 | 类型 | 说明 | | ------------- | --------- | ------------------------------ | | `a_value` | real | 实数,表示新儒略日类型的时间 | | `a_date_time` | tdatetime | 日期时间类型,日期时间,返回值 | 返回:bool ### 示例 ```tsl flag := tryModifiedJulianDateToDateTime(56658.41667, t); if flag then return dateTimeToStr(t); else return 0; // 输出2014-01-01 10:00:00 ``` ## `dateTimeToUnix(a_value)` 声明:function 将TDateTime类型的参数转换成UNIX操作系统的相应时间类型。UNIX操作系统的表示时间的格式是以自1970年1月1日午夜0:00到计时点的秒数 | 参数 | 类型 | 说明 | | --------- | --------- | ------------ | | `a_value` | tdatetime | 日期时间类型 | 返回:integer ### 示例 ```tsl return dateTimeToUnix(strToDateTime('2014-01-01 10:00:00')); // 输出1388570400 ``` ## `unixToDateTime(a_value)` 声明:function 将以UNIX操作系统的相应时间类型的参数AValue转换成TDateTime类型数。UNIX操作系统的表示时间的格式是以自1970年1月1日午夜0:00到计时点的秒数 | 参数 | 类型 | 说明 | | --------- | ------- | -------------------------------- | | `a_value` | integer | 整数,UNIX操作系统的相应时间类型 | 返回:tdatetime ### 示例 ```tsl t := unixToDateTime(1388570400); return dateTimeToStr(t); // 输出2014-01-01 10:00:00 ``` ## `fileDateToDateTime(file_date)` 声明:function 文件时间对标准的时间格式的转换。 | 参数 | 类型 | 说明 | | ----------- | ------- | ---------------- | | `file_date` | integer | 整数,文件时间。 | 返回:tdatetime ### 示例 ```tsl end_t := fileDateToDateTime(1143033856); return dateTimeToStr(end_t); // 输出:2014-01-01 10:00:00 // 差异说明 // 依赖运行时操作系统相关API,与DateTimeToFileDate相对。 // 具体差异表现可参考:FAQ:DateTimeToFileDate ``` ## `dateTimeToFileDate(date_time)` 声明:function 标准时间格式转换成文件的时间格式。 | 参数 | 类型 | 说明 | | ----------- | --------- | ------------ | | `date_time` | tdatetime | 日期时间类型 | 返回:integer ### 示例 ```tsl end_t := strToDateTime('2014-01-01 10:00:00'); file_end_t := dateTimeToFileDate(end_t); return array(end_t, file_end_t); // 比较两种日期输出 // 输出:array(41640.41667,1143033856) // 差异说明 // 转化的结果依赖运行时操作系统相关API,转换结果会存在差异,但是同一系统中,转换与转回是自恰的。 // 即,通过DateTimeToFileDate转换后的结果,再通过FileDateToDateTime转回,可以得到最初未转换之前的值。 // 如: fdate := dateTimeToFileDate(20240525.1430T); echo fdate; // windows下返回:1488548800 Linux中返回:1716618600 t := fileDateToDateTime(fdate); return t; // 都返回20240525.1430T ``` ## `dateTimeGmtToCookieStrw(date)` 声明:function 将日期时间(GMT时间)转为Cookie格式宽字节字符串Fri, 13-Jun-2008 23:01:56 GMT。 | 参数 | 类型 | 说明 | | ------ | --------- | ---------------------------- | | `date` | tdatetime | 日期时间类型,用于转换的时间 | 返回:string ### 示例 ```tsl return dateTimeGmtToCookieStrw(20200723.110633T); // 输出Thu, 23-Jul-2020 11:06:33 GMT ``` ## `dateTimeGmtToHttpStrw(date)` 声明:function 将日期时间(GMT时间)转为HTTP格式宽字节字符串Fri, 13 Jun 2008 23:01:56 GMT。 | 参数 | 类型 | 说明 | | ------ | --------- | ---------------------------- | | `date` | tdatetime | 日期时间类型,用于转换的时间 | 返回:string ### 示例 ```tsl return dateTimeGmtToHttpStrw(20200723.110633T); // 输出Thu, 23 Jul 2020 11:06:33 GMT ``` ## `dateTimeToInternetStrw(date, to_gmt)` 声明:function 将日期转为Internet格式宽字节字符串Friday, 13Jun2008 22:27:04 +0800,当ToGMT为真时,采用GMT时间格式。 | 参数 | 类型 | 说明 | | -------- | --------- | ---------------------------- | | `date` | tdatetime | 日期时间类型,用于转换的时间 | | `to_gmt` | bool | 布尔,是否采用GMT时间格式 | 返回:string ### 示例 ```tsl return dateTimeToInternetStrw(20200723.110633T, 0); // 输出Thu, 23 Jul 2020 11:06:33 +0800 ``` ## `dateTimeToStrw(date_time)` 声明:function 将TDateTime类型的参数DateTime的日期和时间转换成宽字节字符串,格式是短日期加长时间格式 | 参数 | 类型 | 说明 | | ----------- | --------- | ----------------------- | | `date_time` | tdatetime | TDateTime类型,日期时间 | 返回:string ### 示例 ```tsl return dateTimeToStrw(20200720.0930T); // 输出宽字节字符串:2020-07-20 09:30:00 ``` ## `timeToStrw(date_time)` 声明:function 将TDateTime类型的参数DateTime的时间部分转换成宽字节字符串,格式是长时间格式 | 参数 | 类型 | 说明 | | ----------- | --------- | ----------------------- | | `date_time` | tdatetime | TDateTime类型,日期时间 | 返回:string ### 示例 ```tsl return timeToStrw(9.5/24); // 输出宽字节字符串:09:30:00 return timeToStrw(20200720.0930T); // 输出宽字节字符串:09:30:00 ``` ## `dateToStrw(date_time)` 声明:function 将TDateTime类型的参数DateTime的日期部分转换成宽字节字符串,格式是短日期格式 | 参数 | 类型 | 说明 | | ----------- | --------- | ----------------------- | | `date_time` | tdatetime | TDateTime类型,日期时间 | 返回:string ### 示例 ```tsl return dateToStrw(20200720T); // 输出宽字节字符串 2020-07-20 ``` ## `time()` 声明:function 返回TDateTime类型的当前时间,日期部分为0,与系统参数无关。 返回:tdatetime ### 示例 ```tsl return time(); // 输出0.59 ``` ## `Time_Diff(values, order)` 声明:function 计算序列、数组或矩阵的指定阶差分。 | 参数 | 类型 | 说明 | | -------- | ----- | -------------- | | `values` | array | 原始序列或矩阵 | | `order` | any | 差分阶数 | 返回:array ## `Time_AutoCov(values, lag)` 声明:function 计算时间序列在指定滞后阶数下的自协方差。 | 参数 | 类型 | 说明 | | -------- | ----- | -------- | | `values` | array | 时间序列 | | `lag` | any | 滞后阶数 | 返回:float ## `Time_ACF(values)` 声明:function 计算时间序列自相关系数。 | 参数 | 类型 | 说明 | | -------- | ----- | -------- | | `values` | array | 时间序列 | 返回:array ## `Time_ARp(values, order, mode)` 声明:function 估计 AR 模型参数。 | 参数 | 类型 | 说明 | | -------- | ----- | ------------ | | `values` | array | 时间序列 | | `order` | any | AR 阶数 | | `mode` | any | 估计模式参数 | 返回:array ## `Time_MAq(values, order, mode)` 声明:function 估计 MA 模型参数。 | 参数 | 类型 | 说明 | | -------- | ----- | ------------ | | `values` | array | 时间序列 | | `order` | any | MA 阶数 | | `mode` | any | 估计模式参数 | 返回:array ## `Time_ARMA(values, ar_order, ma_order, mode)` 声明:function 估计 ARMA 模型参数。 | 参数 | 类型 | 说明 | | ---------- | ----- | ------------ | | `values` | array | 时间序列 | | `ar_order` | any | AR 阶数 | | `ma_order` | any | MA 阶数 | | `mode` | any | 估计模式参数 | 返回:array ## `Time_ChoseP(values, model_name, criterion)` 声明:function 按准则选择 AR、MA 或 ARMA 模型阶数。 | 参数 | 类型 | 说明 | | ------------ | ------ | ------------------------------------- | | `values` | array | 时间序列 | | `model_name` | string | 模型名;可用 `"AR"`、`"MA"`、`"ARMA"` | | `criterion` | string | 信息准则;常用 `"AIC"`、`"SBIC"` | 返回:any ## `Time_DanielTest(values, alpha)` 声明:function 执行 Daniel 平稳性检验。 | 参数 | 类型 | 说明 | | -------- | ----- | ---------- | | `values` | array | 时间序列 | | `alpha` | float | 显著性水平 | 返回:array ## `Time_ARCHTest(values, lag_order, alpha)` 声明:function 执行 ARCH 效应检验。 | 参数 | 类型 | 说明 | | ----------- | ----- | ---------------- | | `values` | array | 残差或收益率序列 | | `lag_order` | any | 滞后阶数 | | `alpha` | float | 显著性水平 | 返回:array ## `Time_ARCH(values, q_order, forecast_count)` 声明:function 建立 ARCH 模型并输出均值、方差和预测结果。 | 参数 | 类型 | 说明 | | ---------------- | ----- | ---------------- | | `values` | array | 残差或收益率序列 | | `q_order` | any | ARCH 阶数 | | `forecast_count` | any | 预测步数 | 返回:array ## `Time_GARCH(values, model_name)` 声明:function 建立 GARCH 类模型并输出均值、方差和预测结果。 | 参数 | 类型 | 说明 | | ------------ | ------ | ---------------------- | | `values` | array | 残差或收益率序列 | | `model_name` | string | 模型名;常用 `"GARCH"` | 返回:array ## `Time_Analyse(values, model_name, ar_order, ma_order, forecast_count)` 声明:function 按 AR、MA 或 ARMA 模型分析序列并输出预测结果。 | 参数 | 类型 | 说明 | | ---------------- | ------ | ------------------------------------- | | `values` | array | 时间序列 | | `model_name` | string | 模型名;可用 `"AR"`、`"MA"`、`"ARMA"` | | `ar_order` | any | AR 阶数 | | `ma_order` | any | MA 阶数 | | `forecast_count` | any | 预测步数 | 返回:array ## `Time_VolatilitySpillover(x, y, w_type, m, c_type)` 声明:function 波动溢出,底层模型为AR(3)-GARCH(1,1),对时间序列X与Y进行Granger因果检验 | 参数 | 类型 | 说明 | | -------- | ----- | ---------------------------------------------------------------------------------------------------- | | `x` | array | 一维数字数组,时间序列X | | `y` | array | 一维数字数组,时间序列Y | | `w_type` | any | 整型 或 一维数字数组,加权方式,一维数字数组表示可同时返回多种加权方式 | | `m` | any | 整数 或 一维数字数组,滞后阶数,一维数字数组表示同时计算多个M的场景,缺省时M:= array(5,10,20,30,40); | | `c_type` | any | 整数,因果检验类型 | 返回:array