Files
playbook/skills/tsl-api-reference/references/codegen/builtin/datetime.md
T

4420 lines
122 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Builtin - 日期时间
## `compareDate(a, b)`
声明:function
比较时间A所属的日期和时间B所属的日期的大小,返回它们的关系
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ---- | --------- | ---------------------- |
| `a` | tdatetime | 日期时间类型,日期时间 |
| `b` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
result := compareDate(strToDateTime("2011-08-10"), strToDateTime("2011-08-11"));
echo result; // 输出: -1
```
## `compareDateTime(a, b)`
声明:function
比较时间A和时间B的大小,返回它们的关系
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ---- | --------- | ---------------------- |
| `a` | tdatetime | 日期时间类型,日期时间 |
| `b` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
result := compareDateTime(strToDateTime("2011-08-10"), strToDateTime("2011-08-11"));
echo result; // 输出: -1
```
## `compareTime(a, b)`
声明:function
比较A和B的时间部分(不考虑日期部分),返回它们的关系
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ---- | --------- | ---------------------- |
| `a` | tdatetime | 日期时间类型,日期时间 |
| `b` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
result := compareTime(strToDateTime("2011-08-10 01:00:00"), strToDateTime("2011-08-11 01:00:00"));
echo result; // 输出: 0
```
## `currentYear()`
声明:function
返回整数类型的当前年份,与设置的pn_date无关
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
返回:integer
### 示例
```tsl
echo currentYear(); // 输出:当前年份
```
## `date()`
声明:function
返回TDateTime类型的当前日期,时间部分为0,与系统参数无关
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
返回:tdatetime
### 示例
```tsl
echo dateToStr(date()); // 输出:当前日期
```
## `dateOf(a_value)`
声明:function
截取日期时间类型的日期数据
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ------------ |
| `a_value` | tdatetime | 日期时间类型 |
返回:tdatetime
### 示例
```tsl
echo dateToStr(dateOf(now())); // 输出:当前日期
```
## `dateTimeGmtToCookieStr(date)`
声明:function
将日期时间(GMT时间)转为Cookie格式字符串Fri, 13-Jun-2008 23:01:56 GMT
<!-- tags: 日期时间 日期 时间 datetime GMT -->
| 参数 | 类型 | 说明 |
| ------ | --------- | ---------------------------- |
| `date` | tdatetime | 日期时间类型,用于转换的时间 |
返回:string
### 示例
```tsl
end_t := strToDateTime('2014-01-01 10:00:00');
datetime := dateTimeGmtToCookieStr(end_t);
echo datetime; // 输出Wed, 01-Jan-2014 10:00:00 GMT
```
## `dateTimeGmtToCookieStrw(date)`
声明:function
将日期时间(GMT时间)转为Cookie格式宽字节字符串Fri, 13-Jun-2008 23:01:56 GMT
<!-- tags: 日期时间 日期 时间 datetime GMT -->
| 参数 | 类型 | 说明 |
| ------ | --------- | ---------------------------- |
| `date` | tdatetime | 日期时间类型,用于转换的时间 |
返回:string
### 示例
```tsl
echo dateTimeGmtToCookieStrw(20200723.110633T);
// 输出Thu, 23-Jul-2020 11:06:33 GMT
```
## `dateTimeGmtToHttpStr(date)`
声明:function
将日期时间(GMT时间)转为HTTP格式字符串Fri, 13 Jun 2008 23:01:56 GMT
<!-- tags: 日期时间 日期 时间 datetime GMT HTTP -->
| 参数 | 类型 | 说明 |
| ------ | --------- | ------------------------ |
| `date` | tdatetime | 日期时间,用于转换的时间 |
返回:string
### 示例
```tsl
end_t := strToDateTime('2014-01-01 10:00:00');
datetime := dateTimeGmtToHttpStr(end_t);
echo datetime; // 输出:Wed, 01 Jan 2014 10:00:00 GMT
```
## `dateTimeGmtToHttpStrw(date)`
声明:function
将日期时间(GMT时间)转为HTTP格式宽字节字符串Fri, 13 Jun 2008 23:01:56 GMT
<!-- tags: 日期时间 日期 时间 datetime GMT HTTP -->
| 参数 | 类型 | 说明 |
| ------ | --------- | ---------------------------- |
| `date` | tdatetime | 日期时间类型,用于转换的时间 |
返回:string
### 示例
```tsl
echo dateTimeGmtToHttpStrw(20200723.110633T);
// 输出Thu, 23 Jul 2020 11:06:33 GMT
```
## `dateTimeToFileDate(date_time)`
声明:function
标准时间格式转换成文件的时间格式
<!-- tags: 日期时间 转换 编码 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ----------- | --------- | ------------ |
| `date_time` | tdatetime | 日期时间类型 |
返回:integer
### 示例
范例01
```tsl
end_t := strToDateTime('2014-01-01 10:00:00');
file_end_t := dateTimeToFileDate(end_t);
echo trim(toStn(array(end_t, file_end_t)));
// 输出:包含原日期值和文件时间值的数组
// 文件时间值依赖运行时操作系统 API。
```
范例02
```tsl
fdate := dateTimeToFileDate(20240525.1430T);
t := fileDateToDateTime(fdate);
echo fdate, " -> ", dateTimeToStr(t);
// 输出:平台相关文件时间值 -> 2024-05-25 14:30:00
// 同一系统中的转换与转回结果自洽。
```
## `dateTimeToInternetStr(date, to_gmt)`
声明:function
将日期转为Internet格式字符串Friday, 13Jun2008 22:27:04 +0800,当ToGMT为真时,采用GMT时间格式
<!-- tags: 日期时间 日期 时间 datetime GMT -->
| 参数 | 类型 | 说明 |
| -------- | --------- | ---------------------------- |
| `date` | tdatetime | 日期时间类型,用于转换的时间 |
| `to_gmt` | bool | 布尔,是否采用GMT时间格式 |
返回:string
### 示例
```tsl
end_t := strToDateTime('2014-01-01 10:00:00');
datetime := dateTimeToInternetStr(end_t, 0);
echo datetime; // 输出:时区后缀取决于运行环境
```
## `dateTimeToInternetStrw(date, to_gmt)`
声明:function
将日期转为Internet格式宽字节字符串Friday, 13Jun2008 22:27:04 +0800,当ToGMT为真时,采用GMT时间格式
<!-- tags: 日期时间 日期 时间 datetime GMT -->
| 参数 | 类型 | 说明 |
| -------- | --------- | ---------------------------- |
| `date` | tdatetime | 日期时间类型,用于转换的时间 |
| `to_gmt` | bool | 布尔,是否采用GMT时间格式 |
返回:string
### 示例
```tsl
echo dateTimeToInternetStrw(20200723.110633T, 0);
// 输出:时区后缀取决于运行环境
```
## `dateTimeToJulianDate(a_value)`
声明:function
将TDateTime类型的参数转换成儒略日类型。儒略日类型类型是自从格林威治公元前4713年1月一日中午到计时点的天数,包括小数。这种时间用在天文学,地球物理学等需要精确时间的地方
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ------------- |
| `a_value` | tdatetime | TDateTime类型 |
返回:real
### 示例
```tsl
echo dateTimeToJulianDate(strToDateTime('2014-01-01 10:00:00'));
// 输出2456658.91667
```
## `dateTimeToModifiedJulianDate(a_value)`
声明:function
将TDateTime类型的参数转换成新儒略日类型。新儒略日类型类型是在儒略日类型上改进的,计时发法是自从格林威治1958年11月17日午夜到计时点的天数,包括小数
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ------------ |
| `a_value` | tdatetime | 日期时间类型 |
返回:real
### 示例
```tsl
a := dateTimeToModifiedJulianDate(strToDateTime('2014-01-01 10:00:00'));
echo a; // 输出56658.41667
```
## `dateTimeToStr(date_time)`
声明:function
将TDateTime类型的参数DateTime的日期和时间转换成字符串,格式是短日期加长时间格式
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ----------- | --------- | ----------------------- |
| `date_time` | tdatetime | TDateTime类型,日期时间 |
返回:string
### 示例
```tsl
end_t := now();
echo dateTimeToStr(end_t); // 输出当前系统日期时间
```
## `dateTimeToString(result, format, date_time)`
声明:function
根据参数Format给定的格式串将参数DateTime转换成字符串类型存到参数Result中,其中格式串的使用参照FormaTDateTime函数
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ----------- | ---- | ------------------------------- |
| `result` | | 字符串,返回值 |
| `format` | | 字符串,格式串 |
| `date_time` | | TDateTime类型,需转换的日期时间 |
返回:string
### 示例
```tsl
dateTimeToString(result, 'YYYY-MM-DD HH:NN:SS', now());
echo result; // 输出当期系统日期时间
```
## `dateTimeToStrw(date_time)`
声明:function
将TDateTime类型的参数DateTime的日期和时间转换成宽字节字符串,格式是短日期加长时间格式
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ----------- | --------- | ----------------------- |
| `date_time` | tdatetime | TDateTime类型,日期时间 |
返回:string
### 示例
```tsl
echo dateTimeToStrw(20200720.0930T);
// 输出宽字节字符串:2020-07-20 09:30:00
```
## `dateTimeToUnix(a_value)`
声明:function
将TDateTime类型的参数转换成UNIX操作系统的相应时间类型。UNIX操作系统的表示时间的格式是以自1970年1月1日午夜0:00到计时点的秒数
<!-- tags: 日期时间 日期 时间 datetime UNIX -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ------------ |
| `a_value` | tdatetime | 日期时间类型 |
返回:integer
### 示例
```tsl
echo dateTimeToUnix(strToDateTime('2014-01-01 10:00:00'));
// 输出1388570400
```
## `dateToInt(date_time)`
声明:function
将日期类型的EndT转换成整数类型
<!-- tags: 日期时间 转换 编码 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ----------- | --------- | -------- |
| `date_time` | tdatetime | 日期类型 |
返回:integer
### 示例
```tsl
date_time := 40559;
echo dateToInt(date_time);
// 输出:20110116
```
## `dateToStr(date_time)`
声明:function
将TDateTime类型的参数DateTime的日期部分转换成字符串,格式是短日期格式
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ----------- | --------- | ----------------------- |
| `date_time` | tdatetime | TDateTime类型,日期时间 |
返回:string
### 示例
```tsl
end_t := intToDate(20140117);
echo dateToStr(end_t); // 输出 2014-01-17
```
## `dateToStrw(date_time)`
声明:function
将TDateTime类型的参数DateTime的日期部分转换成宽字节字符串,格式是短日期格式
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ----------- | --------- | ----------------------- |
| `date_time` | tdatetime | TDateTime类型,日期时间 |
返回:string
### 示例
```tsl
echo dateToStrw(20200720T); // 输出宽字节字符串 2020-07-20
```
## `dayOf(a_value)`
声明:function
返回参数AValue中包含的日期信息。值域[1,31]
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | -------------- |
| `a_value` | tdatetime | 日期类型,日期 |
返回:integer
### 示例
```tsl
hour := dayOf(strToDateTime('2011-08-08 11:22:06'));
echo hour; // 输出: 8
```
## `dayOfTheMonth(a_value)`
声明:function
返回由参数AValue指定的日期是当月的第几天
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | -------------- |
| `a_value` | tdatetime | 日期类型,日期 |
返回:integer
### 示例
```tsl
day := dayOfTheMonth(strToDateTime('2011-01-22'));
echo day; // 输出: 22
```
## `dayOfTheWeek(a_value)`
声明:function
返回由参数AValue指定的时间是当周的第几天
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | -------------- |
| `a_value` | tdatetime | 日期类型,日期 |
返回:integer
### 示例
```tsl
dayofweek := dayOfTheWeek(strToDateTime('2011-01-03'));
echo dayofweek;
// 输出: 1
```
## `dayOfTheYear(a_value)`
声明:function
返回由参数AValue指定的日期是当年的第几天
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | -------------- |
| `a_value` | tdatetime | 日期类型,日期 |
返回:integer
### 示例
```tsl
d := dayOfTheYear(strToDate('2011-01-03'));
echo d; // 输出: 3
```
## `dayOfWeek(date_time)`
声明:function
返回星期几,1代表星期天,7代表星期六。非ISO8601标准,如果需要使用ISO8601标准,请使用DayOfTheWeek
<!-- tags: 日期时间 返回 获取 日期 时间 datetime ISO8601 -->
| 参数 | 类型 | 说明 |
| ----------- | --------- | ----------------------- |
| `date_time` | tdatetime | TDateTime类型,日期时间 |
返回:integer
### 示例
```tsl
dow := dayOfWeek(encodeDate(2011, 8, 8));
echo dow; // 输出:2
```
## `daysBetween(a_now, athen)`
声明:function
获取参数ANow和参数AThen之间的相距的天数(自然日)。天数的计算同样舍掉了小数尾数
<!-- tags: 日期时间 获取 查询 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------- | --------- | ---------------------- |
| `a_now` | tdatetime | 日期时间类型,日期时间 |
| `athen` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
范例一:
```tsl
days := daysBetween(strToDate('2011-05-01'), strToDate('2011-08-01'));
echo 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'));
echo days; // 输出: 0
```
## `daysInAMonth(a_year, a_month)`
声明:function
返回由Ayear指定的年的第Amonth月共含有多少天
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | ------- | ------------------------- |
| `a_year` | integer | 整数,年,定义域[19999] |
| `a_month` | integer | 整数,月,定义域[112] |
返回:integer
### 示例
```tsl
days := daysInAMonth (2010, 2);
echo days; // 输出28
```
## `daysInAYear(a_year)`
声明:function
返回年份AYear共含有多少天
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| -------- | ------- | ------------------------- |
| `a_year` | integer | 整数,年,定义域[19999] |
返回:integer
### 示例
```tsl
days := daysInAYear (2010);
echo days; // 输出365
```
## `daysInMonth(a_value)`
声明:function
返回AValue所在的月份共含有多少天
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---- |
| `a_value` | tdatetime | 日期 |
返回:integer
### 示例
```tsl
days := daysInMonth (intToDate(20131201));
echo days; // 输出31
```
## `daysInYear(a_value)`
声明:function
返回AValue所在的年份共含有多少天。参数
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | -------- |
| `a_value` | tdatetime | 日期时间 |
返回:integer
### 示例
```tsl
days := daysInYear (date());
echo days; // 输出365
```
## `daySpan(a_now, athen)`
声明:function
获取参数ANow和参数AThen之间的相距的天数
<!-- tags: 日期时间 获取 查询 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------- | --------- | ---------------------- |
| `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);
echo days; // 输出: 731.5
```
## `decodeDate(date_time, year, month, day)`
声明:function
将参数指定的TDateTime类型时间DateTime的年、月、日信息分别存到参数Year,Month,Day中
<!-- tags: 日期时间 解析 parse 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ----------- | --------- | --------------------------------- |
| `date_time` | tdatetime | TDateTime类型,日期时间(输入值) |
| `year` | integer | 整数,年(输出值) |
| `month` | integer | 整数,月(输出值) |
| `day` | integer | 整数,日(输出值) |
返回:integer
### 示例
```tsl
decodeDate(intToDate(20140115), year, month, day);
echo trim(toStn(array(year, month, day )));
// 输出array(2014,1,15)
```
## `decodeDateDay(a_value, a_year, a_day_of_year)`
声明:function
过程,根据参数AValue的时间确定所属的年份以及在当年第多少天,并把分别存到参数AYear, AdayOfYear中
<!-- tags: 日期时间 解析 parse 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------------- | --------- | ------------------ |
| `a_value` | tdatetime | 日期时间类型 |
| `a_year` | integer | 整数,年份,返回值 |
| `a_day_of_year` | integer | 整数,天数,返回值 |
返回:integer
### 示例
```tsl
decodeDateDay(strToDateTime('2011-08-08'), year, dayofyear);
echo trim(toStn(array(year, dayofyear)));
// 输出: array(2011,220)
```
## `decodeDateFully(date_time, year, month, day, dow)`
声明:function
将参数指定的TDateTime类型时间DateTime的年、月、日以及星期几的信息分别存到参数Year,Month,Day,DOW中。如果是闰年,返回真,否则返回假。如果是公元前的年份,则所有参数返回0
<!-- tags: 日期时间 解析 parse 日期 时间 datetime DOW -->
| 参数 | 类型 | 说明 |
| ----------- | --------- | -------------------------------------------------------------------------------- |
| `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, '闰年', '平年');
echo trim(toStn(array(year, month, day, dow, fname)));
// 输出:array(2014,1,15,4,'闰年')
```
## `decodeDateMonthWeek(a_value, a_year, a_month, aweek_of_month, aday_of_week)`
声明:function
根据给定的参数根据参数AValue的时间确定所属的年份、月份以及当月第多少周,当周第多少天,并把分别存到参数Ayear、Amonth、AweekOfMonth、ADayOfWeek中
<!-- tags: 日期时间 解析 parse 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ---------------- | --------- | --------------------------------- |
| `a_value` | tdatetime | 日期类型,分解的日期 |
| `a_year` | integer | 整数,年,定义域[19999],返回值 |
| `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);
echo trim(toStn(array(year, month, weekof_month, day_of_week1))); // 输出: array(2011,8,2,3)
```
## `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中
<!-- tags: 日期时间 解析 parse 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------------- | --------- | ---------------------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
| `a_year` | integer | 整数,年,定义域[19999],返回值 |
| `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);
echo trim(toStn(array(year, month, day, hour, minute, second, millisecond)));
// 输出:array(2011,8,8,12,9,10,990)
```
## `decodeDateWeek(a_value, a_year, aweek_of_year, aday_of_week)`
声明:function
过程,根据一个TDateTime类型的时间,分别分解为年份,周数(属于当年第几周),天数(当周的第几天),并分别存在参数AYear, AWeekOfYear, AdayOfWeek中
<!-- tags: 日期时间 解析 parse 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------------- | --------- | ------------------------------ |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
| `a_year` | integer | 整数,年,返回值 |
| `aweek_of_year` | integer | 整数,月,返回值 |
| `aday_of_week` | integer | 整数,表示当周的第几天,返回值 |
返回:integer
### 示例
```tsl
decodeDateWeek(strToDateTime('2011-08-08'), year, weekofyear, dayofweek);
echo trim(toStn(array( year, weekofyear, dayofweek)));
// 输出: array(2011, 32,1)
```
## `decodeDayOfWeekInMonth(a_value, a_year, a_month, anth_day_of_week, aday_of_week)`
声明:function
过程,根据参数AValue指定的日期得到年份Ayear、月份AMonth、周数AnthDayOfWeek、当周天数AdayOfWeek
<!-- tags: 日期时间 解析 parse 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------------------ | --------- | ---------------- |
| `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(end_t, ayear, amonth, a_nth_day_of_week, a_day_of_week);
echo trim(toStn(array(ayear, amonth, a_nth_day_of_week, a_day_of_week )));
// 输出: array(2011,8,2,3)
```
## `decodeTime(date_time, hour, min, sec, m_sec)`
声明:function
将参数指定DateTime的时间的小时、分钟、秒、毫秒分别存到参数Hour, Min, Sec, MSec中
<!-- tags: 日期时间 解析 parse 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ----------- | --------- | ----------------------- |
| `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);
echo trim(toStn(array(hour, min, sec, msec)));
// 返回 array(13,33,45,500)
```
## `encodeDate(year, month, day)`
声明:function
将参数指定的Year,Month,Day作为年、月、日组成一个TDateTime类型返回
<!-- tags: 日期时间 转换 编码 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------- | ------- | -------- |
| `year` | integer | 整数,年 |
| `month` | integer | 整数,月 |
| `day` | integer | 整数,日 |
返回:tdatetime
### 示例
```tsl
date := encodeDate(2011, 8, 6);
echo date; // 输出:40761
```
## `encodeDateMonthWeek(a_year, a_month, aweek_of_month, aday_of_week)`
声明:function
根据给定参数AYear, AMonth分别作为年、月,AWeekOfMonth作为当月的第几周,AdayOfWeek作为当周的第几天组成一个日期类型值返回,时间部分置0,组成日期返回
<!-- tags: 日期时间 转换 编码 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ---------------- | ------- | ------------------------- |
| `a_year` | integer | 整数,年,定义域[19999] |
| `a_month` | integer | 整数,月,定义域[112] |
| `aweek_of_month` | integer | 整数,当月的第几周 |
| `aday_of_week` | integer | 整数,当周的第几天 |
返回:tdatetime
### 示例
```tsl
monthweek := encodeDateMonthWeek(2011, 8, 2, 1);
echo dateTimeToStr(monthweek); // 输出: 2011-08-08
```
## `encodeDateTime(a_year, a_month, a_day, a_hour, aminute, asecond, amilli_second)`
声明:function
根据给定的参数AYear, AMonth, ADay, AHour, AMinute, ASecond, AmilliSecond分别作为年、月、日、小时、分钟、秒、毫秒组成一个日期时间型数据返回
<!-- tags: 日期时间 转换 编码 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------------- | ------- | ---------------------------------------------------------------------- |
| `a_year` | integer | 整数,年,年,定义域[19999] |
| `a_month` | integer | 整数,月,月,定义域[1,12] |
| `a_day` | integer | 整数,日,日期,定义域[1,31] |
| `a_hour` | integer | 整数,小时,小时,定义域[0,24],如果是24,则要求分钟、秒、毫秒全部为0 |
| `aminute` | integer | 整数,分钟,定义域[059] |
| `asecond` | integer | 整数,秒,定义域[059] |
| `amilli_second` | integer | 整数,毫秒,定义域[0999] |
返回:tdatetime
### 示例
```tsl
timeset := encodeDateTime(2011, 08, 08, 09, 32, 45, 990);
echo dateTimeToStr(timeset); // 输出: 2011-08-08 09:32:45
```
## `encodeDateWeek(a_year, aweek_of_year, aday_of_week)`
声明:function
根据给定的参数AValue年份,以及给定在此年份的第AWeekOfYear周,以及给定的此周的第ADayOfWeek天来确定的,时间部分置0
<!-- tags: 日期时间 转换 编码 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------------- | ------- | ------------------------------------------------ |
| `a_year` | integer | 整数,年,定义域[19999] |
| `aweek_of_year` | integer | 整数,周,定义域[153] |
| `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);
echo dateToStr(week);
// 输出: 2011-01-03
```
## `encodeDayOfWeekInMonth(a_year, a_month, anth_day_of_week, aday_of_week)`
声明:function
根据参数指定的年份Ayear、月份AMonth、周数AnthDayOfWeek、当周天数AdayOfWeek得到一个TDateTime类型值,时间部分置0
<!-- tags: 日期时间 转换 编码 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------------------ | ------- | --------------------------- |
| `a_year` | integer | 整数,年份,定义域[09999] |
| `a_month` | integer | 整数,月份,定义域[012] |
| `anth_day_of_week` | integer | 整数,周数 |
| `aday_of_week` | integer | 整数,当周第几天 |
返回:tdatetime
### 示例
```tsl
// 2013年10月1日是周二,1日至6日不属于这个月的周,从7日(周一)所属周开始算起
echo encodeDayOfWeekInMonth(2013, 10, 2, 1); // 输出41561'2013-10-14'
```
## `encodeTime(hour, min, sec, m_sec)`
声明:function
将参数指定的Hour, Min, Sec, MSec: Integer作为小时、分钟、秒、毫秒组成一个TDateTime类型返回
<!-- tags: 日期时间 转换 编码 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------- | ------- | ---------- |
| `hour` | integer | 整数,小时 |
| `min` | integer | 整数,分钟 |
| `sec` | integer | 整数,秒 |
| `m_sec` | integer | 整数,毫秒 |
返回:tdatetime
### 示例
```tsl
time1 := encodeTime(12, 35, 35, 100);
echo timeToStr(time1); // 输出:12:35:35
```
## `endOfADay(a_year, a_month, a_day)`
声明:function
返回由参数Ayear、Amonth、ADay指定的年月日的结束时间,也就是将日期设定为当天,将时间部分置为下午11:59:59:999,返回类型是TDateTime
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | ------- | -------------------------------- |
| `a_year` | integer | 整数,年,年份,定义域是[19999] |
| `a_month` | integer | 整数,月,月份,定义域是[1,12] |
| `a_day` | integer | 整数,日,日期,定义域是[1,31] |
返回:tdatetime
### 示例
```tsl
year := endOfADay(2015, 1, 5);
echo dateTimeToStr(year); // 输出: 2015-01-05 23:59:59
```
## `endOfAMonth(a_year, a_month)`
声明:function
返回参数AYear指定的年份的AMonth月的最初时间,将日期设定为当月最后一日,将时间部分置为下午11:59:59:999,返回类型是TDateTime
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | ------- | --------------------------- |
| `a_year` | integer | 整数,年,定义域是[19999] |
| `a_month` | integer | 整数,月,定义域是[112] |
返回:tdatetime
### 示例
```tsl
ttime := endOfAMonth(2011, 08);
echo dateTimeToStr(ttime); // 输出: 2011-08-31 23:59:59
```
## `endOfAWeek(a_year, aweek_of_year, aday_of_week)`
声明:function
返回参数AYear指定的年份的第AWeekOfYear周的结束时间,如果不设定参数ADayOfWeek,则取当周最后一个自然日,时间部分为23:59:59:999,返回类型是TDateTime
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------------- | ------- | ------------------------------------------------- |
| `a_year` | integer | 整数,年,定义域是[19999] |
| `aweek_of_year` | integer | 整数,年,表示当年的第几周 |
| `aday_of_week` | integer | 整数,表示当周的第几天,默认为7,既一周的最后一天 |
返回:tdatetime
### 示例
范例一:
```tsl
year := endOfAWeek(2011, 1, 7);
echo dateTimeToStr(year); // 输出: 2011-01-09 23:59:59
```
范例二:
```tsl
year := endOfAWeek (2011, 2, 7);
echo dateTimeToStr(year); // 输出:2011-01-16 23:59:59
```
## `endOfAYear(a_year)`
声明:function
返回参数Ayear指定的年份的结束时间,将日期设定为12月31日,时间部分为23:59:59:999,返回类型是日期时间
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| -------- | ------- | --------------------------- |
| `a_year` | integer | 整数,年,定义域是[19999] |
返回:tdatetime
### 示例
```tsl
year := endOfAYear(2011);
echo dateTimeToStr(year); // 输出: 2011-12-31 23:59:59
```
## `endOfTheDay(a_value)`
声明:function
返回由参数AValue指定的日期的结束时间,也就是将日期设定为当天,时间部分为23:59:59:999,返回类型是日期时间
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:tdatetime
### 示例
```tsl
year := endOfTheDay(strToDateTime('2011-08-08 01:01:10'));
echo dateTimeToStr(year); // 输出: 2011-08-08 23:59:59
```
## `endOfTheMonth(a_value)`
声明:function
返回参数AValue指定的年月的月结束时间,将日期设定为当月最后1个自然日,将时间部分为23:59:59:999,返回类型是TDateTime
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ----------------------- |
| `a_value` | tdatetime | TDateTime类型,日期时间 |
返回:tdatetime
### 示例
```tsl
year := endOfTheMonth(strToDateTime('2011-08-08 12:48:22.990'));
echo dateTimeToStr(year); // 输出: 2011-08-31 23:59:59
```
## `endOfTheWeek(a_value)`
声明:function
返回参数AValue指定的时间所属周的结束时间,将日期设定为当周的最后1个自然日,将时间部分置为下午11:59:59:999,返回类型是TDateTime
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:tdatetime
### 示例
```tsl
year := endOfTheWeek(strToDateTime('2011-08-01'));
echo dateTimeToStr(year); // 输出: 2011-08-07 23:59:59
// 其中2011-08-01是星期一,输出结果2011-08-07是星期天
```
## `endOfTheYear(a_value)`
声明:function
返回参数AValue中所属年的最后一个年自然日的日期时间,如果输入的参数AValue中包含时间数据,则返回的日期中也包含时间数据;否则无时间部分
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ------------------ |
| `a_value` | tdatetime | 日期类型,日期时间 |
返回:tdatetime
### 示例
```tsl
year := endOfTheYear(strToDateTime('2011-08-08 11:22:06.990'));
echo dateTimeToStr(year); // 输出: 2011-12-31 23:59:59
```
## `fileDateToDateTime(file_date)`
声明:function
文件时间对标准的时间格式的转换
<!-- tags: 日期时间 转换 编码 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ----------- | ------- | ---------------- |
| `file_date` | integer | 整数,文件时间。 |
返回:tdatetime
### 示例
```tsl
end_t := fileDateToDateTime(1143033856);
echo dateTimeToStr(end_t);
// 输出:取决于生成该文件时间值的操作系统
// 差异说明
// 依赖运行时操作系统相关API,与DateTimeToFileDate相对。
// 具体差异表现可参考:FAQDateTimeToFileDate
```
## `formaTDateTime(format, date_time)`
声明:function
根据参数Format给定的格式串将参数DateTime转换成字符串类型返回
<!-- tags: 日期时间 格式化 format 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ----------- | --------- | ------------------------------- |
| `format` | string | 字符串,格式串 |
| `date_time` | tdatetime | TDateTime类型,日期时间,默认值 |
返回:string
### 示例
范例01
```tsl
date_time := strToDateTime("2011-08-08 16:27:08");
echo formaTDateTime("C", date_time);
// 输出:2011-08-08 16:27:08
```
范例02
```tsl
date_time := strToDateTime("2011-08-08 16:27:08");
echo formaTDateTime("Dddddd", date_time);
// 输出:取决于当前系统区域设置
```
## `gmtToLocalDateTime(s)`
声明:function
将GMT串转换为日期
<!-- tags: 日期时间 转换 编码 日期 时间 datetime GMT -->
| 参数 | 类型 | 说明 |
| ---- | ------ | --------------------------- |
| `s` | string | 字符串,GMT格式的时间字符串 |
返回:tdatetime
### 示例
```tsl
gmt := "Wed, 01 Jan 2014 10:00:00 GMT ";
datetime := gmtToLocalDateTime(gmt);
echo dateTimeToStr(datetime);
// 输出:取决于当前系统时区
```
## `hourOf(a_value)`
声明:function
返回参数AValue中包含的小时信息。值域[023],同函数是HourOfTheDay
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ------------------ |
| `a_value` | tdatetime | 日期类型,日期时间 |
返回:integer
### 示例
```tsl
hour := hourOf(strToDateTime('2011-08-08 11:22:06'));
echo hour; // 输出: 11
```
## `hourOfTheDay(a_value)`
声明:function
返回由参数AValue指定的时间是当天的第几小时,返回整数,值域是[1,23]
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
hour := hourOfTheDay(strToDateTime('2011-01-05 23:22:22'));
echo hour; // 输出: 23
```
## `hourOfTheMonth(a_value)`
声明:function
返回由参数AValue指定的时间是当月的第几小时
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
hour := hourOfTheMonth(strToDateTime('2011-01-22 10:00:00'));
echo hour; // 输出: 514
```
## `hourOfTheWeek(a_value)`
声明:function
返回由参数AValue指定的时间是当周的第几小时
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ------------ |
| `a_value` | tdatetime | 日期时间类型 |
返回:integer
### 示例
```tsl
hour := hourOfTheWeek(strToDateTime('2011-01-05 10:00:00'));
echo hour; // 输出: 58
```
## `hourOfTheYear(a_value)`
声明:function
返回由参数AValue指定的时间是当年的第几个小时
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
hour := hourOfTheYear(strToDateTime('2011-01-03 10:00:00'));
echo hour; // 输出: 58
```
## `hoursBetween(a_now, athen)`
声明:function
获取参数ANow和参数AThen之间的相距的小时数。小时数的计算同样舍掉了小数尾数
<!-- tags: 日期时间 获取 查询 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------- | --------- | ---------------------- |
| `a_now` | tdatetime | 日期时间类型,日期时间 |
| `athen` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
hours := hoursBetween(strToDateTime('2011-08-01 00:00:00'), strToDateTime('2011-08-01 12:00:00'));
echo hours; // 输出: 12
```
## `hourSpan(a_now, athen)`
声明:function
获取参数ANow和参数AThen之间的相距的小时数
<!-- tags: 日期时间 获取 查询 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------- | --------- | ---------------------- |
| `a_now` | tdatetime | 日期时间类型,日期时间 |
| `athen` | tdatetime | 日期时间类型,日期时间 |
返回:real
### 示例
```tsl
hours := hourSpan(strToDateTime('2010-08-01 00:00:00'), strToDateTime('2012-08-01 12:00:00'));
echo hours; // 输出: 17556
```
## `incAMonth(year, month, day, number_of_months)`
声明:function
返回参数Year、Month、Day指定年、月、日的时间之后NumberOfMonths个月的时间,并把这个时间的年、月、日存到参数Year、Month、Day中
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------------------ | ------- | -------------- |
| `year` | integer | 整数,年,年份 |
| `month` | integer | 整数,月,月份 |
| `day` | integer | 整数,日,日期 |
| `number_of_months` | integer | 整数,月数 |
返回:tdatetime
### 示例
```tsl
year := 2011;
month := 8;
day := 8;
incAMonth(year, month, day, 4);
echo encodeDate(year, month, day); // 输出40885
```
## `incDay(a_value, a_number_of_days)`
声明:function
获取自参数AValue指定的时间向后推移AnumberOfDays天的时间(自然日),参数AnumberOfDays也可以为负值,表示向前推移
<!-- tags: 日期时间 获取 查询 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------------------ | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
| `a_number_of_days` | integer | 整数,表示天数 |
返回:tdatetime
### 示例
```tsl
incdays := incDay(strToDateTime('2010-08-01'), 10);
echo dateToStr(incdays); // 输出: 2010-08-11
```
## `incHour(a_value, a_number_of_hours)`
声明:function
获取自参数AValue指定的时间向后推移AnumberOfHours小时的时间,参数也可以为负值,表示向前推移
<!-- tags: 日期时间 获取 查询 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------------------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
| `a_number_of_hours` | integer | 整数,表示小时数 |
返回:tdatetime
### 示例
```tsl
inchours := incHour(strToDateTime('2010-08-01 00:01:01'), 10);
echo dateTimeToStr(inchours); // 输出: 2010-08-01 10:01:01
```
## `incMilliSecond(a_value, a_number_of_milli_seconds)`
声明:function
获取自参数AValue指定的时间向后推移AnumberOfMilliSeconds毫秒的时间,参数AnumberOfMilliSeconds也可以为负值,表示向前推移
<!-- tags: 日期时间 获取 查询 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------------------------- | --------- | ----------------------- |
| `a_value` | tdatetime | TDateTime类型,日期时间 |
| `a_number_of_milli_seconds` | integer | 整数,表示毫秒数 |
返回:tdatetime
### 示例
```tsl
incmilliseconds := incMilliSecond(strToDateTime('2010-08-01 00:01:01.950'), 50);
echo dateTimeToStr(incmilliseconds); // 输出: 2010-08-01 00:01:02
```
## `incMinute(a_value, a_number_of_minutes)`
声明:function
获取自参数AValue指定的时间向后推移AnumberOfMinutes分钟的时间,参数ANumberOfMinutes也可以为负值,表示向前推移
<!-- tags: 日期时间 获取 查询 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------------------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
| `a_number_of_minutes` | integer | 整数,表示分钟数 |
返回:tdatetime
### 示例
```tsl
incminutes := incMinute(strToDateTime('2010-08-01 00:01:01'), 50);
echo dateTimeToStr(incminutes); // 输出: 2010-08-01 00:51:01
```
## `incMonth(date_time, number_of_months)`
声明:function
返回参数指定的时间DateTime之后NumberOfMonths个月的时间。参数NumberOfMonths也可以为负值,表示向前推移
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------------------ | --------- | ---------------------- |
| `date_time` | tdatetime | 日期时间类型,日期时间 |
| `number_of_months` | integer | 整数,月数 |
返回:tdatetime
### 示例
```tsl
incmonths := incMonth(strToDateTime('2010-08-01'), 2);
echo dateToStr(incmonths); // 输出: 2010-10-01
```
## `incSecond(a_value, a_number_of_seconds)`
声明:function
获取自参数AValue指定的时间向后推移AnumberOfSeconds秒的时间,参数AnumberOfSecond也可以为负值,表示向前推移
<!-- tags: 日期时间 获取 查询 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------------------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
| `a_number_of_seconds` | integer | 整数,表示秒数 |
返回:tdatetime
### 示例
```tsl
incseconds := incSecond(strToDateTime('2010-08-01 00:01:01'), 50);
echo dateTimeToStr(incseconds); // 输出: 2010-08-01 00:01:51
```
## `incWeek(a_value, a_number_of_weeks)`
声明:function
获取自参数AValue指定的时间向后推移AnumberOfWeeks周的时间,参数AnumberOfWeeks也可以为负值,表示向前推移
<!-- tags: 日期时间 获取 查询 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------------------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
| `a_number_of_weeks` | integer | 整数,表示周数 |
返回:tdatetime
### 示例
```tsl
incweeks := incWeek(strToDateTime('2010-08-01'), 1);
echo dateToStr(incweeks); // 输出: 2010-08-08
```
## `incYear(a_value, a_number_of_years)`
声明:function
获取自参数AValue指定的时间向后推移AnumberOfYears年的时间,参数AnumberOfYears也可以为负值,表示向前推移
<!-- tags: 日期时间 获取 查询 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------------------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
| `a_number_of_years` | integer | 整数,表示年数 |
返回:tdatetime
### 示例
```tsl
incyears := incYear(strToDateTime('2010-08-01'), 10);
echo dateToStr(incyears); // 输出: 2020-08-01
```
## `intToDate(rdate)`
声明:function
将整型的日期转换成日期类型的日期
<!-- tags: 日期时间 转换 编码 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------- | ------- | ---- |
| `rdate` | integer | 整型 |
返回:tdatetime
### 示例
```tsl
rdate := 20110116;
echo intToDate(rdate);
// 输出: 40559
```
## `isInLeapYear(a_value)`
声明:function
判断指定的AValue是否是一个闰年。返回一个布尔真假值
<!-- tags: 日期时间 判断 检查 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ------------ |
| `a_value` | tdatetime | 日期时间类型 |
返回:bool
### 示例
```tsl
if isInLeapYear(date) then
echo "this year is a leap year";
else
echo "this year is not a leap year";
// 输出:取决于当前年份
```
## `isLeapYear(year)`
声明:function
返回参数指定的年份Year是否是个闰年,与系统参数无关
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------ | ------- | -------------- |
| `year` | integer | 整数,年,年份 |
返回:bool
### 示例
范例01
```tsl
echo isLeapYear(2000);
// 输出:1
```
范例02
```tsl
echo isLeapYear(2011);
// 输出:0
```
## `isPm(a_value)`
声明:function
判断指定的AValue是否处于下午,就是超过了12:00。返回一个布尔真假值
<!-- tags: 日期时间 判断 检查 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ------------ |
| `a_value` | tdatetime | 日期时间类型 |
返回:bool
### 示例
```tsl
if isPm(time()) then
echo "is PM";
else
echo "is AM";
// 输出:取决于当前时间
```
## `isSameDay(a_value, a_basis)`
声明:function
判断参数AValue和参数Abasis是否在同一天发生。返回值类型是布尔型真假值,如果是同一天,返回真,否则为假
<!-- tags: 日期时间 判断 检查 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | -------- |
| `a_value` | tdatetime | 日期类型 |
| `a_basis` | tdatetime | 日期类型 |
返回:bool
### 示例
```tsl
today := today();
aday := today+2;
if isSameDay(aday, today) then
echo "same day";
else
echo "not same day";
// 输出:not same day
```
## `isToday(a_value)`
声明:function
判断参数AValue的日期是否在今天,返回值类型是布尔型真假值,如果在今天为真,否则为假
<!-- tags: 日期时间 判断 检查 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | -------- |
| `a_value` | tdatetime | 日期类型 |
返回:bool
### 示例
```tsl
today := today();
aday := today+2;
if isToday(aday) then
echo "aday is today ";
else
echo "aday is not today ";
// 输出:aday is not today
```
## `isValidDate(a_year, a_month, a_day)`
声明:function
判断参数指定的的年AYear,月AMonth,日Aday是否是一个有效日期,返回值类型是布尔型真假值
<!-- tags: 日期时间 判断 检查 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | ------- | -------------------- |
| `a_year` | integer | 整数,年,指定的年份 |
| `a_month` | integer | 整数,月,指定的月份 |
| `a_day` | integer | 整数,日,指定的日期 |
返回:bool
### 示例
```tsl
if isValidDate(2011, 8, 34) then
echo "right ";
else
echo "wrong ";
// 输出:wrong
```
## `isValidDateDay(a_year, aday_of_year)`
声明:function
判断参数指定的年以及此年的第ADayOfYear天是否是有效日期。返回值类型是布尔型真假值
<!-- tags: 日期时间 判断 检查 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| -------------- | ------- | ------------------------------ |
| `a_year` | integer | 整数,年,指定的年份 |
| `aday_of_year` | integer | 整数,表示在指定年份中的第几天 |
返回:bool
### 示例
```tsl
if isValidDateDay(2010, 345) then
echo "valid ";
else
echo "not valid ";
// 输出:valid
```
## `isValidDateMonthWeek(a_year, a_month, aweek_of_month, aday_of_week)`
声明:function
判断参数指定的年以及此年的第Amonth月以及此月的第AWeekOfMonth周以及此周的第AdayOfWeek天是否是有效日期。返回值类型是布尔型真假值
<!-- tags: 日期时间 判断 检查 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ---------------- | ------- | ----------------------------------- |
| `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
echo "valid ";
else
echo "not valid ";
// 输出:valid
```
## `isValidDateTime(a_year, a_month, a_day, a_hour, a_minute, a_second, amilli_second)`
声明:function
判断参数指定的日期以及时间是否有效,包括小时AHour ,分钟AMinute,秒ASecond,毫秒AmilliSecond,返回值类型是布尔型真假值
<!-- tags: 日期时间 判断 检查 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------------- | ------- | -------------------- |
| `a_year` | integer | 整数,年,指定的年份 |
| `a_month` | integer | 整数,月,指定的月份 |
| `a_day` | integer | 整数,日,指定的日期 |
| `a_hour` | integer | 整数,小时,小时 |
| `a_minute` | integer | 整数,分钟 |
| `a_second` | integer | 整数,秒 |
| `amilli_second` | integer | 整数,毫秒 |
返回:bool
### 示例
```tsl
if isValidDateTime(2011, 8, 8, 17, 57, 56, 245) then
echo "right ";
else
echo "wrong ";
// 输出:right
```
## `isValidDateWeek(a_year, aweek_of_year, aday_of_week)`
声明:function
判断参数指定的年以及此年的第AweekOfYear周以及此周的第AdayOfWeek天是否是有效日期。返回值类型是布尔型真假值
<!-- tags: 日期时间 判断 检查 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------------- | ------- | ----------------------------- |
| `a_year` | integer | 整数,指定的年份 |
| `aweek_of_year` | integer | 整数,表示在Ayear年份的第几周 |
| `aday_of_week` | integer | 整数,表示指定周的第几天 |
返回:bool
### 示例
```tsl
if isValidDateWeek (2010, 15, 4) then
echo "valid ";
else
echo "not valid ";
// 输出:valid
```
## `isValidTime(a_hour, a_minute, a_second, a_milli_second)`
声明:function
判断参数指定的时间是否有效,包括小时AHour,分钟AMinute,秒ASecond,毫秒AmilliSecond,返回值类型是布尔型真假值
<!-- tags: 日期时间 判断 检查 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ---------------- | ------- | ---------- |
| `a_hour` | integer | 整数,小时 |
| `a_minute` | integer | 整数,分钟 |
| `a_second` | integer | 整数,秒 |
| `a_milli_second` | integer | 整数,毫秒 |
返回:bool
### 示例
```tsl
if isValidTime(17, 48, 45, 678) then
echo "right time ";
else
echo "wrong time ";
// 输出:right time
```
## `julianDateToDateTime(a_value)`
声明:function
将儒略日类型的时间转换成TDateTime类型的时间。儒略日类型类型是自从格林威治公元前4713年1月一日中午到计时点的天数,包括小数。这种时间用在天文学,地球物理学等需要精确时间的地方
<!-- tags: 日期时间 转换 编码 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | ---- | -------------------------- |
| `a_value` | real | 实数,代表儒略日类型的时间 |
返回:tdatetime
### 示例
```tsl
a := julianDateToDateTime(2456658.91667);
echo dateTimeToStr(a); // 输出2014-01-01 10:00:00
```
## `milliSecondOf(a_value)`
声明:function
返回参数AValue中包含的毫秒信息。值域[0,999]
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
millisecond := milliSecondOf(strToDateTime('2011-08-08 11:22:06.990'));
echo millisecond; // 输出: 990
```
## `milliSecondOfTheDay(a_value)`
声明:function
返回由参数AValue指定的时间是当天的第几毫秒,起始点是00:00:00
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
millisecond := milliSecondOfTheDay(strToDateTime('2011-01-05 01:30:01'));
echo millisecond; // 输出: 5401000
```
## `milliSecondOfTheHour(a_value)`
声明:function
返回由参数AValue指定的时间是当前小时的第几毫秒
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
millisecond := milliSecondOfTheHour(strToDateTime('2011-01-05 01:30:01'));
echo millisecond; // 输出: 1801000
```
## `milliSecondOfTheMinute(a_value)`
声明:function
返回由参数AValue指定的时间是当前分钟的第几毫秒
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
millisecond := milliSecondOfTheMinute(strToDateTime('2011-01-05 01:30:01'));
echo millisecond; // 输出: 1000
```
## `milliSecondOfTheMonth(a_value)`
声明:function
返回由参数AValue指定的时间是当月的第几毫秒
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
millisecond := milliSecondOfTheMonth(strToDateTime('2011-01-22 10:00:00'));
echo millisecond; // 输出: 1850400000
```
## `milliSecondOfTheSecond(a_value)`
声明:function
返回由参数AValue指定的时间是当前秒钟的第几毫秒
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
millisecond := milliSecondOfTheSecond(strToDateTime('2011-01-05 01:30:01.990'));
echo millisecond; // 输出:990
```
## `milliSecondOfTheWeek(a_value)`
声明:function
返回由参数AValue指定的时间是当周的第几毫秒
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ------------------ |
| `a_value` | tdatetime | 日期时间类型,日期 |
返回:integer
### 示例
```tsl
millisecond := milliSecondOfTheWeek(strToDateTime('2011-01-05 10:00:00'));
echo millisecond; // 输出: 208800000
```
## `milliSecondOfTheYear(a_value)`
声明:function
返回由参数AValue指定的时间是当年的第几毫秒
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
millisecond := milliSecondOfTheYear(strToDateTime('2011-01-03'));
echo millisecond; // 输出: 172800000
```
## `milliSecondsBetween(a_now, athen)`
声明:function
获取参数ANow和参数AThen之间的相距的毫秒数,返回整数
<!-- tags: 日期时间 获取 查询 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------- | --------- | ---------------------- |
| `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);
echo milliseconds; // 输出: 43200000
```
## `milliSecondSpan(a_now, athen)`
声明:function
获取参数ANow和参数AThen之间的相距的毫秒数
<!-- tags: 日期时间 获取 查询 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------- | --------- | ---------------------- |
| `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 := milliSecondSpan(beg_t, end_t);
echo milliseconds; // 输出:63201600000
```
## `minuteOf(a_value)`
声明:function
返回参数AValue中包含的分钟信息。值域[0,59]
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
minute := minuteOf(strToDateTime('2011-08-08 11:22:06'));
echo minute; // 输出: 22
```
## `minuteOfTheDay(a_value)`
声明:function
返回由参数AValue指定的时间是当天的第几分钟,起始点是00:00:00
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
minute := minuteOfTheDay(strToDateTime('2011-01-05 01:22:22'));
echo minute; // 输出: 82
```
## `minuteOfTheHour(a_value)`
声明:function
返回由参数AValue指定的时间是当前小时的第几分钟
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
minute := minuteOfTheHour(strToDateTime('2011-01-05 01:30:01'));
echo minute; // 输出: 30
```
## `minuteOfTheMonth(a_value)`
声明:function
返回由参数AValue指定的时间是当月的第几分钟
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
minute := minuteOfTheMonth(strToDateTime('2011-01-22 10:00:00'));
echo minute; // 输出: 30840
```
## `minuteOfTheWeek(a_value)`
声明:function
返回由参数AValue指定的时间是当周的第几分钟
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
minute := minuteOfTheWeek(strToDateTime('2011-01-05 10:00:00'));
echo minute; // 输出: 3480
```
## `minuteOfTheYear(a_value)`
声明:function
返回由参数AValue指定的时间是当年的第几分钟
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
minute := minuteOfTheYear(strToDateTime('2011-01-03 10:00:00'));
echo minute; // 输出: 3480
```
## `minutesBetween(a_now, athen)`
声明:function
获取参数ANow和参数AThen之间的相距的分钟数。分钟数的计算同样舍掉了小数尾数
<!-- tags: 日期时间 获取 查询 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------- | --------- | ---------------------- |
| `a_now` | tdatetime | 日期时间类型,日期时间 |
| `athen` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
minutes := minutesBetween(strToDateTime('2011-08-01 00:00:00'), strToDateTime('2011-08-01 12:00:00'));
echo minutes; // 输出: 720
```
## `minuteSpan(a_now, athen)`
声明:function
获取参数ANow和参数AThen之间的相距的分钟数
<!-- tags: 日期时间 获取 查询 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------- | --------- | ---------------------- |
| `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);
echo minutes; // 输出: 1053360
```
## `modifiedJulianDateToDateTime(a_value)`
声明:function
将新儒略日类型的参数AValue转换成TDateTime类型的。新儒略日类型类型是在儒略日类型上改进的,计时发法是自从格林威治1958年11月17日午夜到计时点的天数,包括小数
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | ---- | ---------------------------- |
| `a_value` | real | 实数,表示新儒略日类型的时间 |
返回:tdatetime
### 示例
```tsl
t := modifiedJulianDateToDateTime(56658.41667);
echo dateTimeToStr(t); // 输出2014-01-01 10:00:00
```
## `monthOf(a_value)`
声明:function
返回参数AValue中包含的月份信息。值域[1,12]
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | -------------- |
| `a_value` | tdatetime | 日期类型,日期 |
返回:integer
### 示例
```tsl
month := monthOf(strToDate('2010-08-08'));
echo month; // 输出: 8
```
## `monthOfTheYear(a_value)`
声明:function
返回由参数AValue指定的月份是当年的第几个月,与MonthOf函数相同
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---- |
| `a_value` | tdatetime | 日期 |
返回:integer
### 示例
```tsl
month := monthOfTheYear(strToDate('2011-08-08'));
echo month; // 输出: 8
```
## `monthsBetween(a_now, athen)`
声明:function
获取参数ANow和参数AThen之间的相距的月数。由于月份不具有有相同的长度,所以函数的计算是基于一个每月有30.4375天的假设进行,并且舍掉了小数尾数。因此我们计算从1月1日到1月28日的结果是0,而计算2月1日到3月1日的结果也是0
<!-- tags: 日期时间 获取 查询 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------- | --------- | ---------------------- |
| `a_now` | tdatetime | 日期时间类型,日期时间 |
| `athen` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
months := monthsBetween(strToDateTime('2011-05-01'), strToDateTime('2011-08-01'));
echo months; // 输出: 3
```
## `monthSpan(a_now, athen)`
声明:function
获取参数ANow和参数AThen之间的相距的月数。由于月份不具有相同的长度,所以函数的计算是基于一个每月有30.4375天的假设进行
<!-- tags: 日期时间 获取 查询 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------- | --------- | ---------------------- |
| `a_now` | tdatetime | 日期时间类型,日期时间 |
| `athen` | tdatetime | 日期时间类型,日期时间 |
返回:real
### 示例
```tsl
months := monthSpan(strToDateTime('2010-08-01 00:00:00'), strToDateTime('2012-08-01 12:00:00'));
echo months; // 输出: 24.03
```
## `now()`
声明:function
返回TDateTime类型的当前日期和时间,与系统参数无关
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
返回:tdatetime
### 示例
```tsl
echo now(); // 输出:当前日期时间值
```
## `nthDayOfWeek(a_value)`
声明:function
返回参数AValue指定的日期在当月是第几周,注意,这里的周是代表7天,就是第几个7天。因此,每月的1至7日返回1,8至14日返回2,15至21日返回3,以此类推
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
end_t := strToDateTime("2014-01-06");
week_num := nthDayOfWeek(end_t);
wofm := weekOfTheMonth(end_t);
echo trim(toStn(array(week_num, wofm))); // 输出: array(1,2)
```
## `recodeDate(a_value, a_year, a_month, a_day)`
声明:function
将参数Ayear、Amonth、Aday分别指定年份、月份、日期替换掉参数AValue中的相应的年份、月份、日期信息,保留时间信息,得到的日期时间类型返回
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | -------------------------------------------------------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
| `a_year` | integer | 整数,年份,定义域[09999] |
| `a_month` | integer | 整数,月份,定义域[0,12] |
| `a_day` | integer | 整数,日期,定义域[031],并且要使Ayear、Amonth、Aday组成的时间有效 |
返回:tdatetime
### 示例
```tsl
new_time := recodeDate(strToDateTime("2011-08-10 12:12:12"), 2010, 8, 9);
echo dateTimeToStr(new_time); // 输出: 2010-08-09 12:12:12
```
## `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类型返回
<!-- tags: 日期时间 日期 时间 datetime WORD -->
| 参数 | 类型 | 说明 |
| --------------- | --------- | -------------------------------------------------------------------- |
| `a_value` | tdatetime | 日期时间类型,被替换的日期时间 |
| `a_year` | integer | 整数,年份,定义域[09999] |
| `a_month` | integer | 整数,月份,定义域[0,12] |
| `a_day` | integer | 整数,日期,定义域[012],并且要使Ayear、Amonth、Aday组成的时间有效 |
| `a_hour` | integer | 整数,小时,定义域[0,24] |
| `a_minute` | integer | 整数,分钟,定义域[0,59] |
| `a_second` | integer | 整数,秒钟,定义域[0,59] |
| `amilli_second` | integer | 整数,毫秒,定义域[0999] |
返回:tdatetime
### 示例
```tsl
new_time := recodeDateTime(strToDateTime("2011-08-10 12:12:12.999"), 2010, 8, 10, 10, 8, 9, 100);
echo dateTimeToStr(new_time); // 输出: 2010-08-10 10:08:09
```
## `recodeDay(a_value, a_day)`
声明:function
将参数ADay指定的日期(1至31)替换掉参数AValue中的相应的日期信息,得到的日期类型返回
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ------------------------- |
| `a_value` | tdatetime | 日期类型,日期 |
| `a_day` | integer | 整数,日期,定义域[131] |
返回:tdatetime
### 示例
范例一:
```tsl
try
new_time := recodeDay(strToDateTime("2011-08-10"), 1);
new_time := dateToStr(new_time);
except
new_time := 0;
end;
echo 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;
echo new_time; // 输出:1899-12-30(设置的天超过当月天数时返回零日期,不抛异常)
```
## `recodeHour(a_value, a_hour)`
声明:function
将参数AHour指定的小时(0至24)替换掉参数AValue中的相应的日期信息,得到的日期时间返回
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ------------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
| `a_hour` | integer | 整数,小时,定义域[024] |
返回:tdatetime
### 示例
```tsl
new_time := recodeHour(strToDateTime("2011-08-10 12:12:12"), 1);
echo dateTimeToStr(new_time); // 输出: 2011-08-10 01:12:12
```
## `recodeMilliSecond(a_value, a_milli_second)`
声明:function
将参数ASecond指定的毫秒数(0至999)替换掉参数AValue中的相应的毫秒数信息,得到的日期时间类型返回
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ---------------- | --------- | ---------------------------- |
| `a_value` | tdatetime | :日期时间类型 |
| `a_milli_second` | integer | 整数,毫秒数,定义域[0999] |
返回:tdatetime
### 示例
```tsl
new_time := recodeMilliSecond(strToDateTime("2011-08-10 12:12:12.999"), 100);
echo milliSecondOf (new_time); // 输出: 100
```
## `recodeMinute(a_value, a_minute)`
声明:function
将参数AMinute指定的分钟(0至59)替换掉参数AValue中的相应的分钟信息,得到的日期时间类型返回
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ---------- | --------- | ------------------------- |
| `a_value` | tdatetime | 日期时间类型 |
| `a_minute` | integer | 整数,分钟,定义域[059] |
返回:tdatetime
### 示例
```tsl
new_time := recodeMinute (strToDateTime("2011-08-10 12:12:12"), 9);
echo dateTimeToStr(new_time); // 输出: 2011-08-10 12:09:12
```
## `recodeMonth(a_value, a_month)`
声明:function
将参数AMonth指定的月份替换掉参数 AValue中的相应的月份信息,得到的TDateTime类型返回
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | -------------- |
| `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;
echo new_time; // 输出:2011-10-10
```
范例二:
```tsl
try
new_time := recodeMonth(strToDateTime("2013-3-31"), 4);
new_time := dateTimeToStr(new_time);
except
new_time := dateTimeToStr(0);
end;
echo new_time; // 输出:1899-12-30
```
## `recodeSecond(a_value, a_second)`
声明:function
将参数ASecond指定的秒数(0至59)替换掉参数AValue中的相应的秒数信息,得到的日期时间类型返回
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ---------- | --------- | ------------------------- |
| `a_value` | tdatetime | 日期时间类型 |
| `a_second` | integer | 整数,秒数,定义域[059] |
返回:tdatetime
### 示例
```tsl
new_time := recodeSecond(strToDateTime("2011-08-10 12:12:12"), 9);
echo dateTimeToStr(new_time); // 输出: 2011-08-10 12:12:09
```
## `recodeTime(a_value, a_hour, a_minute, a_second, amilli_second)`
声明:function
将参数Ayear、Amonth、Aday、AHour、AMinute、Asecond、AMilliSecond分别指定小时、分钟、秒钟、毫秒替换掉参数AValue中的相应的小时、分钟、秒钟、毫秒信息,保留日期信息,得到的日期时间类型返回
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------------- | --------- | -------------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
| `a_hour` | integer | 整数,小时,定义域[024] |
| `a_minute` | integer | 整数,分钟,定义域[059] |
| `a_second` | integer | 整数,秒钟,定义域[059] |
| `amilli_second` | integer | 整数,毫秒,定义域[0999] |
返回:tdatetime
### 示例
```tsl
new_time := recodeTime(strToDateTime("2011-08-10 12:12:12.999"), 10, 8, 9, 100);
echo dateTimeToStr(new_time); // 输出: 2011-08-10 10:08:09
```
## `recodeYear(a_value, a_year)`
声明:function
将参数Ayear指定的年份替换掉参数 AValue中的相应的年份信息,得到的日期类型返回
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | -------------- |
| `a_value` | tdatetime | 日期类型,日期 |
| `a_year` | integer | 整数,年份 |
返回:tdatetime
### 示例
范例一:
```tsl
new_time := recodeYear(strToDateTime("2010-08-01"), 2009);
echo 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;
echo new_time; // 输出:0
```
## `sameDate(a, b)`
声明:function
返回布尔型真假值,判断时间A所属的日期和时间B所属的日期是否是同一天,如果是同一天,返回真,否则返回假
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ---- | --------- | ---------------------- |
| `a` | tdatetime | 日期时间类型,日期时间 |
| `b` | tdatetime | 日期时间类型,日期时间 |
返回:bool
### 示例
```tsl
flag := sameDate(strToDateTime("2011-08-10 01:00:00"), strToDateTime("2011-08-10 02:00:00"));
echo flag; // 输出: 1
```
## `sameDateTime(a, b)`
声明:function
判断时间A和时间B是否相等
<!-- tags: 日期时间 判断 检查 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ---- | --------- | ---------------------- |
| `a` | tdatetime | 日期时间类型,日期时间 |
| `b` | tdatetime | 日期时间类型,日期时间 |
返回:bool
### 示例
```tsl
flag := sameDateTime(strToDateTime("2011-08-10"), strToDateTime("2011-08-11"));
echo flag; // 输出: 0
```
## `sameTime(a, b)`
声明:function
判断A和B的时间部分是否相等(不考虑日期部分),如果相等,返回真,否则返回假
<!-- tags: 日期时间 判断 检查 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ---- | --------- | ---------------------- |
| `a` | tdatetime | 日期时间类型,日期时间 |
| `b` | tdatetime | 日期时间类型,日期时间 |
返回:bool
### 示例
```tsl
result := sameTime(strToDateTime("2011-08-10 01:00:00"), strToDateTime("2011-08-11 01:00:00"));
echo result; // 输出: 1
```
## `secondOf(a_value)`
声明:function
返回参数AValue中包含的秒信息。值域[0,59]
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
second := secondOf(strToDateTime('2011-08-08 11:22:06'));
echo second; // 输出: 6
```
## `secondOfTheDay(a_value)`
声明:function
返回由参数AValue指定的时间是当天的第几秒,起始点是00:00:00
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
second := secondOfTheDay(strToDateTime('2011-01-05 01:30:01'));
echo second; // 输出: 5401
```
## `secondOfTheHour(a_value)`
声明:function
返回由参数AValue指定的时间是当前小时的第几秒
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
second := secondOfTheHour(strToDateTime('2011-01-05 01:30:01'));
echo second; // 输出: 1801
```
## `secondOfTheMinute(a_value)`
声明:function
返回由参数AValue指定的时间是当前分钟的第几秒
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
second := secondOfTheMinute(strToDateTime('2011-01-05 01:30:01'));
echo second; // 输出: 1
```
## `secondOfTheMonth(a_value)`
声明:function
返回由参数AValue指定的时间是当月的第几秒种
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
second := secondOfTheMonth(strToDateTime('2011-01-22 10:00:00'));
echo second; // 输出: 1850400
```
## `secondOfTheWeek(a_value)`
声明:function
返回由参数AValue指定的时间是当周的第几秒钟
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
second := secondOfTheWeek(strToDateTime('2011-01-05 10:00:00'));
echo second; // 输出: 208800
```
## `secondOfTheYear(a_value)`
声明:function
返回由参数AValue指定的时间是当年的第几秒种
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------- |
| `a_value` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
second := secondOfTheYear(strToDateTime('2011-01-03'));
echo second; // 输出:172800
```
## `secondsBetween(a_now, athen)`
声明:function
获取参数ANow和参数AThen之间的相距的秒数。秒数的计算同样舍掉了小数尾数
<!-- tags: 日期时间 获取 查询 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------- | --------- | ---------------------- |
| `a_now` | tdatetime | 日期时间类型,日期时间 |
| `athen` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
seconds := secondsBetween(strToDateTime('2011-08-01 00:00:00'), strToDateTime('2011-08-01 12:00:00'));
echo seconds; // 输出: 43200
```
## `secondSpan(a_now, athen)`
声明:function
获取参数ANow和参数AThen之间的相距的秒数
<!-- tags: 日期时间 获取 查询 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------- | --------- | ---------------------- |
| `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);
echo seconds; // 输出: 63201600
```
## `startOfADay(a_year, a_month, a_day)`
声明:function
返回由参数Ayear、Amonth、ADay指定的年月日的最初时间,也就是将日期设定为当天,将时间部分置0
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | ------- | --------------------------- |
| `a_year` | integer | 整数,年,定义域是[19999] |
| `a_month` | integer | 整数,月,定义域是[112] |
| `a_day` | integer | 整数,日,定义域是[131] |
返回:tdatetime
### 示例
```tsl
year := startOfADay(2011, 8, 8);
echo dateTimeToStr(year); // 输出: 2011-08-08
```
## `startOfAMonth(a_year, a_month)`
声明:function
返回参数AYear指定的年份的AMonth月的最初时间,将日期设定为当月第1自然日,时间部分为0
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | ------- | --------------------------- |
| `a_year` | integer | 整数,年,定义域是[19999] |
| `a_month` | integer | 整数,月,定义域是[112] |
返回:tdatetime
### 示例
```tsl
tdate := startOfAMonth(2011, 08);
echo dateTimeToStr(tdate); // 输出: 2011-08-01
```
## `startOfAWeek(a_year, aweek_of_year, aday_of_week)`
声明:function
返回参数AYear指定的年份的第AWeekOfYear周的最初时间,将日期设定为当周的第1日,无时间部分
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------------- | ------- | ----------------------------------------------- |
| `a_year` | integer | 整数,年,定义域是[19999] |
| `aweek_of_year` | integer | 整数,年,表示当年的第几周 |
| `aday_of_week` | integer | 整数,表示当周的第几天,默认为1,既一周的最开始 |
返回:tdatetime
### 示例
范例一:
```tsl
// 取当年的第一个完整周
year := startOfAWeek(2011, 1, 1);
echo dateTimeToStr(year); // 输出: 2011-01-03
```
范例二:
```tsl
year := startOfAWeek(2011, 2, 1);
echo dateTimeToStr(year); // 输出:2011-01-10
```
## `startOfAYear(a_year)`
声明:function
返回参数Ayear指定的年份的年初时间,返回的年初日期无时间部分
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| -------- | ------- | --------------------------- |
| `a_year` | integer | 整数,年,定义域是[19999] |
返回:tdatetime
### 示例
```tsl
year := startOfAYear(2011);
echo dateTimeToStr(year); // 输出: 2011-01-01
```
## `startOfTheDay(a_value)`
声明:function
返回由参数AValue指定的日期的最初时间,也就是将日期设定为当天,将时间部分置0,返回类型是日期
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ----------------------- |
| `a_value` | tdatetime | TDateTime类型,日期时间 |
返回:tdatetime
### 示例
```tsl
year := startOfTheDay(strToDateTime('2011-08-08 23:59:59'));
echo dateTimeToStr(year); // 输出: 2011-08-08
```
## `startOfTheMonth(a_value)`
声明:function
返回参数AValue指定的年月的月初时间,将日期设定为当月的第1自然日,时间部分为0
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ----------------------- |
| `a_value` | tdatetime | TDateTime类型,日期时间 |
返回:tdatetime
### 示例
```tsl
year := startOfTheMonth(strToDateTime('2011-08-08 12:48:22.990'));
echo dateTimeToStr(year); // 输出: 2011-08-01
```
## `startOfTheWeek(a_value)`
声明:function
返回参数AValue指定的时间所属周的最初时间,将日期设定为当周的第1个自然日,时间部分为0
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ----------------------- |
| `a_value` | tdatetime | TDateTime类型,日期时间 |
返回:tdatetime
### 示例
```tsl
year := startOfTheWeek(strToDateTime('2011-08-07'));
echo dateTimeToStr(year); // 输出: 2011-08-01
// 其中2011-08-07是星期天,2011-08-01是星期一
```
## `startOfTheYear(a_value)`
声明:function
返回参数AValue中包含的年份的最初时间,将日期设定为1月1日,无时间部分
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | -------------- |
| `a_value` | tdatetime | 日期类型,日期 |
返回:tdatetime
### 示例
```tsl
d_time := startOfTheYear(strToDateTime('2011-08-08 11:22:06.990'));
echo dateTimeToStr(d_time); // 输出: 2011-01-01
```
## `strToDate(s)`
声明:function
将字符串S转换成TDateTime类型的日期
<!-- tags: 日期时间 转换 编码 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ---- | ------ | ---------------------------------------- |
| `s` | string | 字符串,日期的字符串类型,如"2014-01-17" |
返回:datetime
### 示例
```tsl
echo dateToInt(strToDate("2014-01-17"));
// 输出:20140117
```
## `strToDateDef(s, default)`
声明:function
将字符串S转换成TDateTime类型的日期,如果转换不成功,则返回Default指定的默认日期
<!-- tags: 日期时间 转换 编码 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ---------------------------------------- |
| `s` | string | 字符串,日期的字符串类型,如"2014-01-17" |
| `default` | tdatetime | TDateTime类型,默认值 |
返回:tdatetime
### 示例
```tsl
echo strToDateDef("2010-02-30", date()); // 转换失败输出当前日期40763
```
## `strToDateTime(s)`
声明:function
将字符串S转换成TDateTime类型的日期和时间
<!-- tags: 日期时间 转换 编码 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ---- | ------ | ----------------------------------------------------- |
| `s` | string | 字符串,日期时间的字符串类型,如"2014-01-17 10:00:00" |
返回:datetime
### 示例
```tsl
value := strToDateTime("2014-01-17 10:20:30");
echo trim(toStn(array(dateToInt(value), hourOf(value), minuteOf(value), secondOf(value))));
// 输出:array(20140117,10,20,30)
```
## `strToDateTimeDef(s, default)`
声明:function
将字符串S转换成TDateTime类型的日期和时间,如果转换不成功,则返回Default指定的默认日期和时间
<!-- tags: 日期时间 转换 编码 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ----------------------------------------------------- |
| `s` | string | 字符串,日期时间的字符串类型,如"2014-01-17 10:00:00" |
| `default` | tdatetime | TDateTime类型,默认值 |
返回:tdatetime
### 示例
```tsl
echo strToDateTimeDef("2011-08-08 16:61:16 ", now()); // 输出当前系统日期时间
```
## `strToTime(s)`
声明:function
将字符串S转换成TDateTime类型的时间
<!-- tags: 日期时间 转换 编码 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ---- | ------ | -------------------------------------- |
| `s` | string | 字符串,时间的字符串类型,如"15:20:34" |
返回:datetime
### 示例
```tsl
value := strToTime("15:20:34");
echo trim(toStn(array(hourOf(value), minuteOf(value), secondOf(value))));
// 输出:array(15,20,34)
```
## `strToTimeDef(s, default)`
声明:function
将字符串S转换成TDateTime类型的时间,如果转换不成功,则返回Default指定的默认时间
<!-- tags: 日期时间 转换 编码 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | -------------------------------------- |
| `s` | string | 字符串,时间的字符串类型,如"15:20:34" |
| `default` | tdatetime | TDateTime类型,默认值 |
返回:tdatetime
### 示例
```tsl
time := strToTimeDef("15:61:34 ", time());
echo time; // 输出当前系统时间
```
## `time()`
声明:function
返回TDateTime类型的当前时间,日期部分为0,与系统参数无关
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
返回:tdatetime
### 示例
```tsl
echo time(); // 输出:当前时间值
```
## `timeOf(a_value)`
声明:function
返回一个只含有时间信息的TDateTime类型,天数部分设为0,就是1899年12月30日
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ------------ |
| `a_value` | tdatetime | 日期时间类型 |
返回:tdatetime
### 示例
范例01
```tsl
echo timeOf(now());
// 输出:当前日期时间中的时间部分
```
范例02
```tsl
end_t := strToDateTime("2014-01-17 10:00:00");
echo timeToStr(timeOf(end_t));
// 输出:10:00:00
```
## `timeToStr(date_time)`
声明:function
将TDateTime类型的参数DateTime的时间部分转换成字符串,格式是长时间格式
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ----------- | --------- | ----------------------- |
| `date_time` | tdatetime | TDateTime类型,日期时间 |
返回:string
### 示例
范例01
```tsl
echo timeToStr(0.5);
// 输出:12:00:00
```
范例02
```tsl
echo timeToStr(now());
// 输出:当前系统时间
```
## `timeToStrw(date_time)`
声明:function
将TDateTime类型的参数DateTime的时间部分转换成宽字节字符串,格式是长时间格式
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ----------- | --------- | ----------------------- |
| `date_time` | tdatetime | TDateTime类型,日期时间 |
返回:string
### 示例
范例01
```tsl
echo timeToStrw(9.5 / 24);
// 输出:09:30:00
```
范例02
```tsl
echo timeToStrw(20200720.0930T);
// 输出:09:30:00
```
## `today()`
声明:function
返回今天的日期,不含时间部分
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
返回:tdatetime
### 示例
```tsl
datetime := today();
echo dateToStr(datetime); // 输出:当天日期
```
## `tomorrow()`
声明:function
返回明天的日期,不含时间部分
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
返回:tdatetime
### 示例
```tsl
datetime := tomorrow();
echo dateToStr(datetime); // 输出:明天日期
```
## `tryEncodeDate(year, month, day, date)`
声明:function
将参数指定的Year,Month,Day作为年、月、日组成一个TDateTime类型寸到参数Date中。如果转换成功,函数返回真,否则返回假
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------- | --------- | ------------ |
| `year` | integer | 整数,年 |
| `month` | integer | 整数,月 |
| `day` | integer | 整数,日 |
| `date` | tdatetime | 日期,返回值 |
返回:bool
### 示例
范例01:编码有效日期。
```tsl
if tryEncodeDate(2011, 12, 25, date) then
echo date;
else
echo "encode error";
// 输出:40902
```
范例02:编码无效日期。
```tsl
if tryEncodeDate(2011, 12, 32, date) then
echo date;
else
echo "encode error";
// 输出:encode error
```
## `tryEncodeDateDay(a_year, a_day_of_year, a_value)`
声明:function
过程,根据给定的参数AYear年份、以及指定在给定年份的第ADayofYear天来生成一个日期并存到参数AValue中,时间部分置0
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------------- | --------- | ------------------ |
| `a_year` | integer | 整数,年份, |
| `a_day_of_year` | integer | 整数,当年的第几天 |
| `a_value` | tdatetime | 日期类型,返回值 |
返回:bool
### 示例
```tsl
flag := tryEncodeDateDay(2011, 1, atime);
echo trim(toStn(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中。函数返回一个布尔型真假值,以表明日期是否有效转化
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ---------------- | --------- | ------------------------- |
| `a_year` | integer | 整数,年,定义域[19999] |
| `a_month` | integer | 整数,月,定义域[112] |
| `aweek_of_month` | integer | 整数,当月的第几周 |
| `aday_of_week` | integer | 整数,当周的第几天 |
| `a_value` | tdatetime | 日期类型,组成的日期 |
返回:bool
### 示例
```tsl
flag := tryEncodeDateMonthWeek(2011, 1, 1, 1, atime);
echo trim(toStn(array(flag, dateTimeToStr(atime)))); // 输出: array(1.0,'2011-01-03')
```
## `tryEncodeDateTime(a_year, a_month, a_day, a_hour, aminute, asecond, amilli_second, a_value)`
声明:function
根据给定的参数AYear, AMonth, ADay, AHour, AMinute, ASecond, AmilliSecond分别作为年、月、日、小时、分钟、秒、毫秒组成一个日期时间型变量存到参数AValue中,并返回一个布尔型真假值,表示是否是个有效的日期
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------------- | --------- | ---------------------------------------------------------------- |
| `a_year` | integer | 整数,年,定义域[19999] |
| `a_month` | integer | 整数,月,定义域[112] |
| `a_day` | integer | 整数,日,定义域[131] |
| `a_hour` | integer | 整数,小时,定义域[0,24],如果是24,则要求分钟、秒、毫秒全部为0 |
| `aminute` | integer | 整数,分钟,定义域[0,59] |
| `asecond` | integer | 整数,秒,定义域[059] |
| `amilli_second` | integer | 整数,毫秒,定义域[0999] |
| `a_value` | tdatetime | 日期时间类型,组成的日期,返回值 |
返回:bool
### 示例
```tsl
flag := tryEncodeDateTime(2011, 8, 10, 10, 01, 01, 999, atime);
echo trim(toStn(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。返回布尔值,表示是否是个有效的日期
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ---------------- | --------- | ------------------------------------------------ |
| `a_year` | integer | 整数,年,定义域[19999] |
| `a_week_of_year` | integer | 整数,周数,定义域[1,53] |
| `a_value` | tdatetime | 日期类型,返回值 |
| `aday_of_week` | integer | 整数,定义域[1,7],并小于当周属于当年的最大天数 |
返回:bool
### 示例
```tsl
flag := tryEncodeDateWeek(2011, 1, atime, 1);
echo trim(toStn(array(flag, dateTimeToStr(atime)))); // 输出: array(1,'2011-01-03')
```
## `tryEncodeDayOfWeekInMonth(a_year, a_month, anth_day_of_week, aday_of_week, a_value)`
声明:function
跟EncodeDayOfWeekInMonth函数非常类似。根据参数指定的年份Ayear、月份AMonth、周数AnthDayOfWeek、当周天数AdayOfWeek得到一个TDateTime类型值,存到参数AValue中,时间部分置0。函数返回一个真假值,如果给定的参数能够得到合法的日期就返回真,否则返回假
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------------------ | --------- | ---------------------------- |
| `a_year` | integer | 整数,年份,定义域[09999] |
| `a_month` | integer | 整数,月份,定义域[012] |
| `anth_day_of_week` | integer | 整数,周数 |
| `aday_of_week` | integer | 整数,当周第几天 |
| `a_value` | tdatetime | 日期类型,组成的日期,返回值 |
返回:bool
### 示例
```tsl
tryEncodeDayOfWeekInMonth(2013, 10, 2, 1, newtime);
echo dateTimeToStr(newtime);
// 输出: 2013-10-14
```
## `tryEncodeTime(hour, min, sec, m_sec, time)`
声明:function
将参数指定的Hour, Min, Sec, MSec: Integer作为小时、分钟、秒、毫秒组成一个TDateTime类型寸到参数Time中。如果转换成功,函数返回真,否则返回假
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------- | --------- | ---------------- |
| `hour` | integer | 整数,小时 |
| `min` | integer | 整数,分钟 |
| `sec` | integer | 整数,秒 |
| `m_sec` | integer | 整数,毫秒 |
| `time` | tdatetime | 日期,组成的日期 |
返回:bool
### 示例
```tsl
if tryEncodeTime(12, 20, 30, 200, time) then
echo timeToStr(time);
else
echo "encode error";
// 输出:12:20:30
```
## `tryJulianDateToDateTime(a_value, a_date_time)`
声明:function
将儒略日类型的时间转换成TDateTime类型的时间并存到参数AdateTime中。函数返回布尔型真假值,表示是否可以转换成功
<!-- tags: 日期时间 转换 编码 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------------- | --------- | ---------------------------------------- |
| `a_value` | real | 实数,代表儒略日类型的时间 |
| `a_date_time` | tdatetime | 日期时间类型,转化成功的日期时间,返回值 |
返回:bool
### 示例
```tsl
flag := tryJulianDateToDateTime(2456658.91667, t);
if flag then
echo dateTimeToStr(t);
else
echo 0;
// 输出:2014-01-01 10:00:00
```
## `tryModifiedJulianDateToDateTime(a_value, a_date_time)`
声明:function
与ModifiedJulianDateToDateTime函数非常类似,将新儒略日类型的参数AValue转换成TDateTime类型的值存到参数AdateTime中。函数返回布尔型真假值,表示是否转换成功
<!-- tags: 日期时间 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------------- | --------- | ------------------------------ |
| `a_value` | real | 实数,表示新儒略日类型的时间 |
| `a_date_time` | tdatetime | 日期时间类型,日期时间,返回值 |
返回:bool
### 示例
```tsl
flag := tryModifiedJulianDateToDateTime(56658.41667, t);
if flag then
echo dateTimeToStr(t);
else
echo 0;
// 输出:2014-01-01 10:00:00
```
## `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类型值),来告诉函数此参数对应的响应时间部分不需替换
<!-- tags: 日期时间 日期 时间 datetime WORD -->
| 参数 | 类型 | 说明 |
| --------------- | --------- | -------------------------------------------------------------------- |
| `a_value` | tdatetime | 日期时间类型,被替换的日期时间 |
| `a_year` | integer | 整数,年份,定义域[09999] |
| `a_month` | integer | 整数,月份,定义域[0,12] |
| `a_day` | integer | 整数,日期,定义域[012],并且要使Ayear、Amonth、Aday组成的时间有效 |
| `a_hour` | integer | 整数,小时,定义域[024] |
| `a_minute` | integer | 整数,分钟,定义域[0,59] |
| `a_second` | integer | 整数,秒钟,定义域[0,59] |
| `amilli_second` | integer | 整数,毫秒,定义域[0999] |
| `aresult` | tdatetime | 日期时间类型,替换后的日期时间 |
返回:bool
### 示例
```tsl
tryRecodeDateTime(strToDateTime("2011-08-10 12:12:12.999"), 2010, 8, 10, 10, 8, 9, 100, aresult);
echo dateTimeToStr(aresult); // 输出: 2010-08-10 10:08:09
```
## `tryStrToDate(s, value)`
声明:function
将字符串S转换成TDateTime类型的日期并存到参数Value中。如果转换成功,则返回真,否则返回假
<!-- tags: 日期时间 转换 编码 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------- | --------- | ---------------------------------------- |
| `s` | string | 字符串,日期的字符串类型,如"2014-01-17" |
| `value` | tdatetime | 日期,转化后的日期,返回值 |
返回:bool
### 示例
```tsl
if tryStrToDate("2010-02-04 ", date) then
echo date; // 输出:40213
```
## `tryStrToDateTime(s, value)`
声明:function
将字符串S转换成TDateTime类型的日期和时间并存到参数Value中。如果转换成功,则返回真,否则返回假
<!-- tags: 日期时间 转换 编码 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------- | --------- | ---------------------------------------- |
| `s` | string | 字符串,日期的字符串类型,如"2014-01-17" |
| `value` | tdatetime | 日期时间,返回值 |
返回:bool
### 示例
```tsl
if tryStrToDateTime("2010-02-04 16:11:35 ", datetime) then
echo dateTimeToStr(datetime); // 输出:2010-02-04 16:11:35
```
## `tryStrToTime(s, value)`
声明:function
将字符串S转换成TDateTime类型的时间并存到参数Value中。如果转换成功,则返回真,否则返回假
<!-- tags: 日期时间 转换 编码 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------- | --------- | ---------------------------------------- |
| `s` | string | 字符串,日期的字符串类型,如"2014-01-17" |
| `value` | tdatetime | 日期时间,转换结果(输出参数) |
返回:bool
### 示例
```tsl
if tryStrToTime("15:52:35", time) then
echo timeToStr(time); // 输出:15:52:35
```
## `unixToDateTime(a_value)`
声明:function
将以UNIX操作系统的相应时间类型的参数AValue转换成TDateTime类型数。UNIX操作系统的表示时间的格式是以自1970年1月1日午夜0:00到计时点的秒数
<!-- tags: 日期时间 日期 时间 datetime UNIX -->
| 参数 | 类型 | 说明 |
| --------- | ------- | -------------------------------- |
| `a_value` | integer | 整数,UNIX操作系统的相应时间类型 |
返回:tdatetime
### 示例
```tsl
t := unixToDateTime(1388570400);
echo dateTimeToStr(t);
// 输出2014-01-01 10:00:00
```
## `weekOfTheMonth(a_value)`
声明:function
返回指定日期在当月中的周序号
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ------------------ |
| `a_value` | tdatetime | 要计算周序号的日期 |
返回:integer
### 示例
```tsl
echo weekOfTheMonth(20260731T);
// 输出:5
```
## `weekOfTheMonth(a_value, a_year, a_month)`
声明:function
返回指定日期在当月中的周序号。该重载同时接受年份和月份参数
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | ------------------ |
| `a_value` | tdatetime | 要计算周序号的日期 |
| `a_year` | integer | 所属年份参数 |
| `a_month` | integer | 所属月份参数 |
返回:integer,值域为 1 到 6。
### 示例
```tsl
echo weekOfTheMonth(strToDateTime("2011-01-22"), 2011, 1), "\n";
// 输出:3
```
## `weekOfTheYear(a_value)`
声明:function
返回由参数AValue指定的时间是处于当年的第几个周,与函数WeekOf相同。返回整数,值域是[1,53]
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | -------------- |
| `a_value` | tdatetime | 日期类型,日期 |
返回:integer
### 示例
```tsl
week := weekOfTheYear(strToDate('2011-01-03'));
echo week; // 输出: 1
```
## `weeksBetween(a_now, athen)`
声明:function
获取参数ANow和参数AThen之间的相距的周数。周数的计算同样舍掉了小数尾数。例如我们计算从1月1日的12:00 AM到1月6日的Jan 6 at 11:58 PM的结果是0,因为差了1分钟
<!-- tags: 日期时间 获取 查询 日期 时间 datetime AM PM -->
| 参数 | 类型 | 说明 |
| ------- | --------- | ---------------------- |
| `a_now` | tdatetime | 日期时间类型,日期时间 |
| `athen` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
weeks := weeksBetween(strToDateTime('2011-05-01'), strToDateTime('2011-08-01'));
echo weeks; // 输出: 13
```
## `weeksInAYear(a_year)`
声明:function
返回年份AYear共含有多少个周。周数的认定是依据ISO8601的标准,关于此标准的解释请参阅附注
<!-- tags: 日期时间 返回 获取 日期 时间 datetime ISO8601 -->
| 参数 | 类型 | 说明 |
| -------- | ------- | ------------------------- |
| `a_year` | integer | 整数,年,定义域[19999] |
返回:integer
### 示例
```tsl
num := weeksInAYear (2010);
echo num; // 输出52
```
## `weeksInYear(a_value)`
声明:function
返回AValue所在的年份共含有多少个周。周数的认定是依据ISO8601的标准,关于此标准的解释请参阅附注
<!-- tags: 日期时间 返回 获取 日期 时间 datetime ISO8601 -->
| 参数 | 类型 | 说明 |
| --------- | --------- | -------- |
| `a_value` | tdatetime | 日期类型 |
返回:integer
### 示例
```tsl
num := weeksInYear(strToDateTime('2015-01-01'));
echo num; // 输出:53
```
## `weekSpan(a_now, athen)`
声明:function
获取参数ANow和参数AThen之间的相距的周数
<!-- tags: 日期时间 获取 查询 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------- | --------- | ---------------------- |
| `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);
echo weeks; // 输出: 104.5
```
## `withinPastDays(a_now, athen, a_days)`
声明:function
判断时间ANow和时间AThen的时间间隔是否在ADays自然日内,与系统参数无关
<!-- tags: 日期时间 判断 检查 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| -------- | --------- | -------------------------- |
| `a_now` | tdatetime | 日期时间类型,查找时间 |
| `athen` | tdatetime | 日期时间类型,查找起始时间 |
| `a_days` | integer | 整数,天数 |
返回:bool
### 示例
范例一:
```tsl
flag := withinPastDays(strToDate('2011-01-01'), strToDate('2011-01-11'), 10);
echo flag; // 输出: 1
```
范例二:
```tsl
flag := withinPastDays(strToDate('2011-01-01'), strToDate('2011-01-12'), 10);
echo flag; // 输出: 0
```
## `withinPastHours(a_now, athen, a_hours)`
声明:function
判断时间ANow和时间AThen的时间间隔是否在AHours个小时内
<!-- tags: 日期时间 判断 检查 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | -------------------------- |
| `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);
echo flag; // 输出: 1
```
范例二:
```tsl
flag := withinPastHours(strToDateTime('2011-01-01 00:00:00'), strToDateTime('2011-01-01 11:00:00'), 10);
echo flag; // 输出: 0
```
## `withinPastMilliSeconds(a_now, athen, a_milli_seconds)`
声明:function
判断时间ANow和时间AThen的时间间隔是否在AMilliSeconds毫秒内
<!-- tags: 日期时间 判断 检查 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ----------------- | --------- | -------------------------- |
| `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);
echo flag; // 输出: 1
```
## `withinPastMinutes(a_now, athen, a_minutes)`
声明:function
判断时间ANow和时间AThen的时间间隔是否在AMinutes分钟内
<!-- tags: 日期时间 判断 检查 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ----------- | --------- | -------------------------- |
| `a_now` | tdatetime | 日期时间类型,查找时间 |
| `athen` | tdatetime | 日期时间类型,查找起始时间 |
| `a_minutes` | integer | 整数,分钟个数 |
返回:bool
### 示例
范例01
```tsl
flag := withinPastMinutes(strToDateTime('2011-01-01 10:00:00'), strToDateTime('2011-01-01 10:10:00'), 10);
echo flag;
// 输出:1
```
范例02
```tsl
flag := withinPastMinutes(strToDateTime('2011-01-01 10:00:00'), strToDateTime('2011-01-01 10:11:00'), 10);
echo flag;
// 输出:0
```
## `withinPastMonths(a_now, athen, a_months)`
声明:function
判断时间ANow和时间AThen的时间间隔是否在Amonths月内
<!-- tags: 日期时间 判断 检查 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ---------- | --------- | -------------------------- |
| `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);
echo flag; // 输出: 1
```
范例二:
```tsl
flag := withinPastMonths(strToDateTime('2011-01-05'), strToDateTime('2011-07-07'), 5);
echo flag; // 输出: 0
```
## `withinPastSeconds(a_now, athen, a_seconds)`
声明:function
判断时间ANow和时间AThen的时间间隔是否在ASeconds秒内
<!-- tags: 日期时间 判断 检查 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ----------- | --------- | -------------------------- |
| `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);
echo flag; // 输出: 1
```
范例二:
```tsl
flag := withinPastSeconds(strToDateTime('2011-01-01 10:00:00'), strToDateTime('2011-01-01 10:00:11'), 10);
echo flag; // 输出: 0
```
## `withinPastWeeks(a_now, athen, a_weeks)`
声明:function
判断时间ANow和时间AThen的时间间隔是否在AWeeks周内
<!-- tags: 日期时间 判断 检查 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | -------------------------- |
| `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);
echo 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);
echo flag; // 输出: 0
```
## `withinPastYears(a_now, athen, a_years)`
声明:function
判断时间ANow和时间AThen的时间间隔是否在Ayears年内
<!-- tags: 日期时间 判断 检查 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | -------------------------- |
| `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);
echo flag; // 输出: 1
```
范例二:
```tsl
// //2010年1月5日至2013年1月5日之间,相隔 3年,因此,判断为不在2年内
flag := withinPastYears(strToDateTime('2010-01-05'), strToDateTime('2013-01-05'), 2);
echo flag; // 输出: 0
```
## `yearOf(a_value)`
声明:function
返回参数AValue中包含的年份信息。值域[19999]
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| --------- | --------- | -------- |
| `a_value` | tdatetime | 日期类型 |
返回:integer
### 示例
```tsl
year := yearOf(strToDate('2010-08-08'));
echo year;
// 输出: 2010
```
## `yearsBetween(a_now, athen)`
声明:function
获取参数ANow和参数AThen之间的相距的年数。由于年份不具有相同的长度,例如闰年比非闰年长一天,所以函数的计算是基于一个每年有365.25天的假设进行,并且舍掉了小数尾数。因此我们计算一个非闰年的1月1日到12月31日的结果是0年,而计算一个闰年的1月1日到12月31日的结果是1年
<!-- tags: 日期时间 获取 查询 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------- | --------- | ---------------------- |
| `a_now` | tdatetime | 日期时间类型,日期时间 |
| `athen` | tdatetime | 日期时间类型,日期时间 |
返回:integer
### 示例
```tsl
years := yearsBetween(strToDateTime('2009-01-01 00:00:00'), strToDateTime('2011-01-01 23:59:59.999'));
echo years; // 输出: 2
```
## `yearSpan(a_now, athen)`
声明:function
获取参数ANow和参数AThen之间的相距的年数。由于年份不具有相同的长度,例如闰年比非闰年长一天,所以函数的计算是基于一个每年有365.25天的假设进行
<!-- tags: 日期时间 获取 查询 日期 时间 datetime -->
| 参数 | 类型 | 说明 |
| ------- | --------- | ---------------------- |
| `a_now` | tdatetime | 日期时间类型,日期时间 |
| `athen` | tdatetime | 日期时间类型,日期时间 |
返回:real
### 示例
```tsl
years := yearSpan(strToDateTime('2010-08-01 00:00:00'), strToDateTime('2012-08-01 12:00:00'));
echo years; // 输出: 2.00274
```
## `yesterday()`
声明:function
返回昨天的日期,不含时间部分
<!-- tags: 日期时间 返回 获取 日期 时间 datetime -->
返回:tdatetime
### 示例
```tsl
datetime := yesterday();
echo dateToStr(datetime); // 输出:昨天日期
```