Date类¶
Date类指定SQL日期数据项的抽象。Date类还添加了格式化和解析操作,以支持日期值的ACCI转义语法。
Date()¶
日期类构造函数。
| 语法 | 描述 |
|---|---|
| Date(); | 创建空Date对象。 |
Date(
|
创建Date对象的副本。 |
Date( const Environment *envp, int year = 1, unsigned int month = 1, unsigned int day = 1, unsigned int hour = 0, unsigned int minute = 0, unsigned int seconds = 0); |
使用整数参数创建Date对象。 |
| 参数 | 描述 |
|---|---|
| year | -4712到9999,除了0 |
| month | 1到12 |
| day | 1到31 |
| minutes | 0到59 |
| seconds | 0到59 |
daysBetween()¶
返回当前日期对象与指定日期之间的天数。
语法
IntervalDS daysBetween(
const Date &date) const;
| 语法 | 描述 |
|---|---|
| date | 用于计算的日期。 |
fromText()¶
将日期对象设置为由字符串表示的值。
| 参数 | 描述 |
|---|---|
void fromText( const string &datestr const string &fmt const string &nlsParam const Environment * envp |
要转换为日期对象的日期字符串 格式字符串;默认是DD-MON-YY。 NLS参数字符串。如果指定了nlsParam,这将确定用于转换 的NLS参数。如果没有指定nlsParam,则从envp获取NLS参数。 ACCI环境句柄 |
void fromText( const UString &datestr const UString &fmt const UString &nlsParam const Environment * envp |
要转换为日期对象的日期字符串 格式字符串;默认是DD-MON-YY。 NLS参数字符串。如果指定了nlsParam,这将确定用于转换 的NLS参数。如果没有指定nlsParam,则从envp获取NLS参数。 ACCI环境句柄 |
getDate()¶
以日期组件的形式返回日期:年、月、日、小时、分钟、秒。
语法
void getDate(
int &year,
unsigned int &month,
unsigned int &day,
unsigned int &hour,
unsigned int &min,
unsigned int &seconds) const;
| 参数 | 描述 |
|---|---|
| year | 组成日期的年份 |
| month | 组成日期的月份 |
| day | 组成日期的天 |
| hour | 组成日期的小时 |
| min | 组成日期的分钟 |
| seconds | 组成日期的秒 |
operator=()¶
将等号(=)符号右侧的date对象分配给等号(=)符号左侧的date对象。
语法
Date& operator=(
const Date &d);
| 参数 | 描述 |
|---|---|
| date | 被分配的日期对象。 |
operator==()¶
比较指定的日期。如果日期相等,则返回TRUE;否则,返回FALSE。
语法
bool operator==(
const Date &first,
const Date &second);
| 参数 | 描述 |
|---|---|
| first | 要比较的第一个时间 |
| second | 要比较的第二个时间 |
operator!=()¶
与指定的日期相比较。如果日期不相等,则返回TRUE;否则,返回FALSE。
语法
bool operator==(
const Date &first,
const Date &second);
| 参数 | 描述 |
|---|---|
| first | 要比较的第一个时间 |
| second | 要比较的第二个时间 |
operator>()¶
比较指定的日期。如果第一个日期相对于第二个日期是在将来,那么返回TRUE;否则,返回FALSE。如果任一日期为空,则返回FALSE。如果日期类型不同,则返回FALSE。
语法
bool operator>(
const Date &first,
const Date &second);
| 参数 | 描述 |
|---|---|
| first | 要比较的第一个时间 |
| second | 要比较的第二个时间 |
operator>=()¶
比较指定的日期。如果第一个日期相对于第二个日期是在将来或日期是相等的,那么返回TRUE;否则,返回FALSE。如果任一日期为空,则返回FALSE。如果日期类型不同,则返回FALSE。
语法
bool operator>=(
const Date &first,
const Date &second);
| 参数 | 描述 |
|---|---|
| first | 要比较的第一个时间 |
| second | 要比较的第二个时间 |
operator<()¶
比较指定的日期。如果第一个日期在第二个日期之前,那么返回TRUE;否则,返回FALSE。如果任一日期为空,则返回FALSE。如果日期类型不同,则返回FALSE。
语法
bool operator<(
const Date &first,
const Date &second);
| 参数 | 描述 |
|---|---|
| first | 要比较的第一个时间 |
| second | 要比较的第二个时间 |
operator<=()¶
比较指定的日期。如果第一个日期在第二个日期之前,或者日期是相等的,那么返回TRUE;否则,返回FALSE。如果任一日期为空,则返回FALSE。如果日期类型不同,则返回FALSE。
语法
bool operator<=(
const Date &first,
const Date &second);
| 参数 | 描述 |
|---|---|
| first | 要比较的第一个时间 |
| second | 要比较的第二个时间 |
setDate()¶
将日期设置为指定的值。
语法
void setDate(
int year = 1,unsigned int month = 1,
unsigned int day = 1,unsigned int hour = 0,
unsigned int minute = 0,unsigned int seconds = 0);
| 参数 | 描述 |
|---|---|
| year | 指定年份值的参数。有效值是-4713到9999。 |
| month | 指定月份值的参数。有效值是1到12。 |
| day | 指定日值的参数。有效值是1到31。 |
| hour | 指定小时值的参数。有效值是0到23。 |
| min | 指定分钟值的参数。有效值是0到59。 |
| second | 指定秒值的参数。有效值是0到59。 |
toText()¶
返回使用fmt和nlsParam格式化的日期值的字符串。
| 参数 | 描述 |
|---|---|
string toText( const string &fmt const string &nlsParam |
格式字符串;默认是DD-MON-YY。(默认值为空) NLS参数字符串。如果指定了nlsParam,这将确定用于转换的 NLS参数。如果没有指定nlsParam,则从envp获取NLS参数。 |
UString toText( const UString &fmt const UString &nlsParam |
格式字符串;默认是DD-MON-YY。(默认值为空) NLS参数字符串。如果指定了nlsParam,这将确定用于转换的 NLS参数。如果没有指定nlsParam,则从envp获取NLS参数。 |
toZone()¶
返回从一个时区转换为另一个时区的日期值。
语法
Date toZone(
const string &zone1,
const string &zone2) const;
| 参数 | 描述 |
|---|---|
| zone1 | 表示要转换的时区的字符串。 |
| zone2 | 表示要转换到的时区的字符串。 |