c语言时间处理函数

c语言时间处理函数,第1张

C语言的标准库函数包括一系列日期和时间处理函数,它们都在头文件中说明。

在头文件中定义了三种类型:time_t,struct tm和clock_t。

下面列出了这些函数。

time_t time(time_t timer);

double difftime(time_t time1,time_t time2);

struct tm gmtime(const time_t timer);

struct tm localtime(const time_t timer);

char asctime(const struct tm timeptr);

char ctime(const time_t timer);

size_t strftime(char s,size_t maxsize,const char format,const struct tm timeptr);

time_t mktime(struct tm timeptr);

clock_t clock(void);

具体应用举例

asctime(将时间和日期以字符串格式表示)

相关函数

time,ctime,gmtime,localtime

表头文件

#i nclude

定义函数

char asctime(const struct tm timeptr);

函数说明

asctime()将参数timeptr所指的tm结构中的信息转换成真实世界所使用的时间日期表示方法,然后将结果以字符串形态返回。

此函数已经由时区转换成当地时间,字符串格式为:"Wed Jun 30 21:49:08 1993\n"

返回值

若再调用相关的时间日期函数,此字符串可能会被破坏。此函数与ctime不同处在于传入的参数是不同的结构。

附加说明

返回一字符串表示目前当地的时间日期。

范例

#i nclude

main()

{

time_t timep;

time (&timep);

printf("%s",asctime(gmtime(&timep)));

}

执行

Sat Oct 28 02:10:06 2000

 

ctime(将时间和日期以字符串格式表示)

相关函数

time,asctime,gmtime,localtime

表头文件

#i nclude

定义函数

char ctime(const time_t timep);

函数说明

ctime ()将参数timep所指的time_t结构中的信息转换成真实世界所使用的时间日期表示方法,然后将结果以字符串形态返回。

此函数已经由时区转换成当地时间,字符串格式为"Wed Jun 30 21 :49 :08 1993\n"。若再调用相关的时间日期函数,此字符串可能会被破坏。

返回值

返回一字符串表示目前当地的时间日期。

范例

#i nclude

main()

{

time_t timep;

time (&timep);

printf("%s",ctime(&timep));

}

执行

Sat Oct 28 10 : 12 : 05 2000

 

gettimeofday(取得目前的时间)

相关函数

time,ctime,ftime,settimeofday

表头文件

#i nclude

#i nclude

定义函数

int gettimeofday ( struct timeval tv , struct timezone tz )

函数说明

gettimeofday()会把目前的时间有tv所指的结构返回,当地时区的信息则放到tz所指的结构中。

timeval结构定义为:

struct timeval{

long tv_sec; /秒/

long tv_usec; /微秒/

};

timezone 结构定义为:

struct timezone{

int tz_minuteswest; /和Greenwich 时间差了多少分钟/

int tz_dsttime; /日光节约时间的状态/

};

上述两个结构都定义在/usr/include/sys/timeh。tz_dsttime 所代表的状态如下

DST_NONE /不使用/

DST_USA /美国/

DST_AUST /澳洲/

DST_WET /西欧/

DST_MET /中欧/

DST_EET /东欧/

DST_CAN /加拿大/

DST_GB /大不列颠/

DST_RUM /罗马尼亚/

DST_TUR /土耳其/

DST_AUSTALT /澳洲(1986年以后)/

返回值

成功则返回0,失败返回-1,错误代码存于errno。附加说明EFAULT指针tv和tz所指的内存空间超出存取权限。

范例

#i nclude

#i nclude

main(){

struct timeval tv;

struct timezone tz;

gettimeofday (&tv , &tz);

printf("tv_sec; %d\n", tv,tv_sec) ;

printf("tv_usec; %d\n",tvtv_usec);

printf("tz_minuteswest; %d\n", tztz_minuteswest);

printf("tz_dsttime, %d\n",tztz_dsttime);

}

执行

tv_sec: 974857339

tv_usec:136996

tz_minuteswest:-540

tz_dsttime:0

 

gmtime(取得目前时间和日期)

相关函数

time,asctime,ctime,localtime

表头文件

#i nclude

定义函数

struct tmgmtime(const time_ttimep);

函数说明

gmtime()将参数timep 所指的time_t 结构中的信息转换成真实世界所使用的时间日期表示方法,然后将结果由结构tm返回。

结构tm的定义为

struct tm

{

int tm_sec;

int tm_min;

int tm_hour;

int tm_mday;

int tm_mon;

int tm_year;

int tm_wday;

int tm_yday;

int tm_isdst;

};

int tm_sec 代表目前秒数,正常范围为0-59,但允许至61秒

int tm_min 代表目前分数,范围0-59

int tm_hour 从午夜算起的时数,范围为0-23

int tm_mday 目前月份的日数,范围01-31

int tm_mon 代表目前月份,从一月算起,范围从0-11

int tm_year 从1900 年算起至今的年数

int tm_wday 一星期的日数,从星期一算起,范围为0-6

int tm_yday 从今年1月1日算起至今的天数,范围为0-365

int tm_isdst 日光节约时间的旗标

此函数返回的时间日期未经时区转换,而是UTC时间。

返回值

返回结构tm代表目前UTC 时间

范例

#i nclude

main(){

char wday[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};

time_t timep;

struct tm p;

time(&timep);

p=gmtime(&timep);

printf("%d%d%d",(1900+p->tm_year), (1+p->tm_mon),p->tm_mday);

printf("%s%d;%d;%d\n", wday[p->tm_wday], p->tm_hour, p->tm_min, p->tm_sec);

}

执行

2000/10/28 Sat 8:15:38

 

localtime(取得当地目前时间和日期)

相关函数

time, asctime, ctime, gmtime

表头文件

#i nclude

定义函数

struct tm localtime(const time_t timep);

函数说明

localtime()将参数timep所指的time_t结构中的信息转换成真实世界所使用的时间日期表示方法,然后将结果由结构tm返回。

结构tm的定义请参考gmtime()。此函

数返回的时间日期已经转换成当地时区。

返回值

返回结构tm代表目前的当地时间。

范例

#i nclude

main(){

char wday[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};

time_t timep;

struct tm p;

time(&timep);

p=localtime(&timep); /取得当地时间/

printf ("%d%d%d ", (1900+p->tm_year),( l+p->tm_mon), p->tm_mday);

printf("%s%d:%d:%d\n", wday[p->tm_wday],p->tm_hour, p->tm_min, p->tm_sec);

}

执行

2000/10/28 Sat 11:12:22

 

mktime(将时间结构数据转换成经过的秒数)

相关函数

time,asctime,gmtime,localtime

表头文件

#i nclude

定义函数

time_t mktime(strcut tm timeptr);

函数说明

mktime()用来将参数timeptr所指的tm结构数据转换成从公元1970年1月1日0时0分0 秒算起至今的UTC时间所经过的秒数。

返回值

返回经过的秒数。

范例

/ 用time()取得时间(秒数),利用localtime()

转换成struct tm 再利用mktine()将struct tm转换成原来的秒数/

#i nclude

main()

{

time_t timep;

strcut tm p;

time(&timep);

printf("time() : %d \n",timep);

p=localtime(&timep);

timep = mktime(p);

printf("time()->localtime()->mktime():%d\n",timep);

}

执行

time():974943297

time()->localtime()->mktime():974943297

 

settimeofday(设置目前时间)

相关函数

time,ctime,ftime,gettimeofday

表头文件

#i nclude

#i nclude

定义函数

int settimeofday ( const struct timeval tv,const struct timezone tz);

函数说明

settimeofday()会把目前时间设成由tv所指的结构信息,当地时区信息则设成tz所指的结构。详细的说明请参考gettimeofday()。

注意,只有root权限才能使用此函数修改时间。

返回值

成功则返回0,失败返回-1,错误代码存于errno。

错误代码

EPERM 并非由root权限调用settimeofday(),权限不够。

EINVAL 时区或某个数据是不正确的,无法正确设置时间。

 

time(取得目前的时间)

相关函数

ctime,ftime,gettimeofday

表头文件

#i nclude

定义函数

time_t time(time_t t);

函数说明

此函数会返回从公元1970年1月1日的UTC时间从0时0分0秒算起到现在所经过的秒数。如果t 并非空指针的话,

此函数也会将返回值存到t指针所指的内存。

返回值

成功则返回秒数,失败则返回((time_t)-1)值,错误原因存于errno中。

范例

#i nclude

mian()

{

int seconds= time((time_t)NULL);

printf("%d\n",seconds);

}

Date and Time Functions: <timeh>

The header <timeh> declares types and functions for manipulating date and time Some functions process local time,

which may differ from calendar time, for example because of time zone clock_t and time_t are arithmetic types

representing times, and struct tm holds the components

of a calendar time:

int tm_sec; seconds after the minute (0,61)

int tm_min; minutes after the hour (0,59)

int tm_hour; hours since midnight (0,23)

int tm_mday; day of the month (1,31)

int tm_mon; months since January (0,11)

int tm_year; years since 1900

int tm_wday; days since Sunday (0,6)

int tm_yday; days since January 1 (0,365)

int tm_isdst; Daylight Saving Time flag

tm_isdst is positive if Daylight Saving Time is in effect, zero if not, and negative if the information is not available

clock_t clock(void)

clock returns the processor time used by the program since the beginning of execution, or -1 if unavailable

clock()/CLK_PER_SEC is a time in

seconds

time_t time(time_t tp)

time returns the current calendar time or -1 if the time is not available If tp is not NULL,

the return value is also assigned to tp

double difftime(time_t time2, time_t time1)

difftime returns time2-time1 expressed in seconds

time_t mktime(struct tm tp)

mktime converts the local time in the structure tp into calendar time in the same representation used by time

The components will have values

in the ranges shown mktime returns the calendar time or -1 if it cannot be represented

The next four functions return pointers to static objects that may be overwritten by other calls

char asctime(const struct tm tp)

asctimetp into a string of the form

Sun Jan 3 15:14:13 1988\n\0

char ctime(const time_t tp)

ctime converts the calendar time tp to local time; it is equivalent to

asctime(localtime(tp))

struct tm gmtime(const time_t tp)

gmtime converts the calendar time tp into Coordinated Universal Time (UTC) It returns NULL if UTC is not available

The name gmtime has historical significance

struct tm localtime(const time_t tp)

localtime converts the calendar time tp into local time

size_t strftime(char s, size_t smax, const char fmt, const struct tm tp)

strftime formats date and time information from tp into s according to fmt, which is analogous to a printf format

Ordinary characters (including the terminating '\0') are copied into s Each %c is replaced as described below,

using values appropriate for the local environment

No more than smax characters are placed into s strftime returns the number of characters, excluding the '\0',

or zero if more than smax characters were produced

%a abbreviated weekday name

%A full weekday name

%b abbreviated month name

%B full month name

%c local date and time representation

%d day of the month (01-31)

%H hour (24-hour clock) (00-23)

%I hour (12-hour clock) (01-12)

%j day of the year (001-366)

%m month (01-12)

%M minute (00-59)

%p local equivalent of AM or PM

%S second (00-61)

%U week number of the year (Sunday as 1st day of week) (00-53)

%w weekday (0-6, Sunday is 0)

%W week number of the year (Monday as 1st day of week) (00-53)

%x local date representation

%X local time representation

%y year without century (00-99)

%Y year with century

%Z time zone name, if any

%% %

SQL数据库中有各种不同的函数,下面为您介绍SQL中的时间函数,如果您是才接触SQL的新手,不妨一看,相信会对您有所帮助。

--基于时间SQL函数--

getdate()

--返回当前系统日期和时间。

select

getdate()

DateAdd

--在向指定日期加上一段时间的基础上,返回新的

datetime

值。

DATEADD

(

datepart

,

number,

date

)

--例:向当天的时间增加5天

select

dateadd(dd,5,getdate())

datediff

--返回跨两个指定日期的日期和时间边界数。

DATEDIFF

(

datepart

,

startdate

,

enddate

)

--例:返回2005-01-01与当天有多少天

select

datediff(dd,'2005-01-01',getdate())

--把时间字段的数据变为年月

Select

Convert(Varchar(6),GetDate(),112)

--字符串变时间

select

convert(datetime,left(@t,len(@t)-4)+':'+left(right(@t,4),2)+':'+right(@t,2))

ISDATE

--确定输入表达式是否为有效的日期

DATEPART

--返回代表指定日期的指定日期部分的整数

DATEPART

(

datepart

,

date

)

--如:返回当前是几月

select

datepart(mm,getdate())

DATENAME

--返回代表指定日期的指定日期部分的字符串

--datepart

,datename的区别:前者返回是整数,后者返回是字符串。

a) 函数ADDDATE(date ,INTERVAL expr type ) ADDDATE(expr ,days )

函数使用说明: 当被第二个参数的 INTERVAL 格式激活后, ADDDATE() 就是 DATE_ADD() 的同义词。相关函数 SUBDATE() 则是 DATE_SUB() 的同义词。对于 INTERVAL 参数上的信息 ,请参见关于 DATE_ADD() 的论述。

b) 函数 ADDTIME(expr ,expr2 )

函数使用说明: ADDTIME() 将 expr2 添加至 expr 然后返回结果。 expr 是一个时间或时间日期表达式,而 expr2 是一个时间表达式。

c) 函数 CONVERT_TZ(dt ,from_tz ,to_tz )

函数使用说明: CONVERT_TZ() 将时间日期值 dt 从 from_tz 给出的时区转到 to_tz 给出的时区,然后返回结果值。关于可能指定的时区的详细论述,若自变量无效,则这个函数会返回 NULL

d) 函数 CURDATE()

函数使用说明:将当前日期按照 'YYYY-MM-DD' 或 YYYYMMDD 格式的值返回,具体格式根据函数用在字符串或是数字语境中而定。

e) 函数 CURRENT_DATE CURRENT_DATE()

函数使用说明: CURRENT_DATE 和 CURRENT_DATE() 是的同义词

f) 函数 CURTIME()

函数使用说明: 将当前时间以 'HH:MM:SS' 或 HHMMSS 的格式返回, 具体格式根据函数用在字符串或是数字语境中而定。

g) 函数 CURRENT_TIME, CURRENT_TIME()

函数使用说明: CURRENT_TIME 和 CURRENT_TIME() 是 CURTIME() 的同义词。

h) 函数 CURRENT_TIMESTAMP, CURRENT_TIMESTAMP()

函数使用说明: CURRENT_TIMESTAMP 和 CURRENT_TIMESTAMP() 是 NOW() 的同义词

i) 函数 DATE(expr )

函数使用说明: 提取日期或时间日期表达式expr 中的日期部分。

j) 函数 DATEDIFF(expr ,expr2 )

函数使用说明: DATEDIFF() 返回起始时间 expr 和结束时间 expr2 之间的天数。 Expr 和 expr2 为日期或 date-and-time表达式。计算中只用到这些值的日期部分。

k) 函数 DATE_ADD(date ,INTERVAL expr type ) DATE_SUB(date ,INTERVAL expr type )

函数使用说明:这些函数执行日期运算。 date 是一个 DATETIME 或 DATE 值,用来指定起始时间。 expr 是一个表达式,用来指定从起始日期添加或减去的时间间隔值。 Expr 是一个字符串 ; 对于负值的时间间隔,它可以以一个 ‘-’ 开头。 type 为关键词,它指示了表达式被解释的方式。

l) 函数 DATE_FORMAT(date ,format )

函数使用说明:根据 format 字符串安排 date 值的格式。

m) 函数 DAY(date )

函数使用说明: DAY() 和 DAYOFMONTH() 的意义相同

n) 函数 DAYNAME(date )

函数使用说明:返回 date 对应的工作日名称。

o) 函数 DAYOFMONTH(date )

函数使用说明:返回 date 对应的该月日期,范围是从 1 到 31

p) 函数 DAYOFWEEK(date )

函数使用说明:返回 date (1 = 周日 , 2 = 周一 , , 7 = 周六 ) 对应的工作日索引。这些索引值符合 ODBC 标准

q) 函数 DAYOFYEAR(date )

函数使用说明:返回date 对应的一年中的天数,范围是从 1 到366 。

r) 函数 EXTRACT(type FROM date )

函数使用说明: EXTRACT() 函数所使用的时间间隔类型说明符同 DATE_ADD() 或 DATE_SUB() 的相同 , 但它从日期中提取其部分,而不是执行日期运算。

s) 函数FROM_DAYS(N )

函数使用说明: 给定一个天数 N , 返回一个 DATE 值。

t) 函数 FROM_UNIXTIME(unix_timestamp ) FROM_UNIXTIME(unix_timestamp ,format )

函数使用说明:返回'YYYY-MM-DD HH:MM:SS' 或YYYYMMDDHHMMSS 格式值的unix_timestamp 参数表示,具体格式取决于该函数是否用在字符串中或是数字语境中。 若format 已经给出,则结果的格式是根据format 字符串而定。 format 可以包含同DATE_FORMAT() 函数输入项列表中相同的说明符。

u) 函数 GET_FORMAT(DATE|TIME|DATETIME, 'EUR'|'USA'|'JIS'|'ISO'|'INTERNAL')

函数使用说明:返回一个格式字符串。这个函数在同 DATE_FORMAT() 及 STR_TO_DATE() 函数结合时很有用

v) 函数 HOUR(time )

函数使用说明:返回 time 对应的小时数。对于日时值的返回值范围是从 0 到 23

w) 函数 LAST_DAY(date )

函数使用说明:获取一个日期或日期时间值,返回该月最后一天对应的值。若参数无效,则返回 NULL 。

x) 函数 LOCALTIME, LOCALTIME()

函数使用说明: LOCALTIME 及 LOCALTIME() 和 NOW() 具有相同意义。

y) 函数 LOCALTIMESTAMP, LOCALTIMESTAMP()

函数使用说明: LOCALTIMESTAMP 和 LOCALTIMESTAMP() 和 NOW() 具有相同意义。

z) 函数 MAKEDATE(year ,dayofyear )

函数使用说明:给出年份值和一年中的天数值,返回一个日期。 dayofyear 必须大于 0 ,否则结果为 NULL 。

aa) 函数 MAKETIME(hour ,minute ,second )

函数使用说明: 返回由 hour 、 minute 和 second 参数计算得出的时间值

bb) 函数 CROSECOND(expr )

函数使用说明:从时间或日期时间表达式expr 返回微秒值,其数字范围从 0 到 999999 。

cc) 函数 MINUTE(time )

函数使用说明:返回 time 对应的分钟数 , 范围是从 0 到 59 。

dd) 函数 MONTH(date )

函数使用说明:返回 date 对应的月份,范围时从 1 到 12 。

ee) 函数 MONTHNAME(date )

函数使用说明: 返回 date 对应月份的全名

ff) 函数 NOW()

函数使用说明:返回当前日期和时间值,其格式为 'YYYY-MM-DD HH:MM:SS' 或 YYYYMMDDHHMMSS , 具体格式取决于该函数是否用在字符串中或数字语境中。

gg) 函数 PERIOD_ADD(P ,N )

函数使用说明:添加 N 个月至周期 P ( 格式为 YYMM 或 YYYYMM) ,返回值的格式为 YYYYMM 。注意周期参数 P 不是 日期值。

hh) 函数 PERIOD_DIFF(P1 ,P2 )

函数使用说明:返回周期 P1 和 P2 之间的月份数。 P1 和 P2 的格式应该为 YYMM 或 YYYYMM 。注意周期参数 P1 和 P2 不是 日期值。

ii) 函数 QUARTER(date )

函数使用说明:返回 date 对应的一年中的季度值,范围是从 1 到 4

jj) 函数 SECOND(time )

函数使用说明:返回 time 对应的秒数 , 范围是从 0 到 59 。

kk) 函数 SEC_TO_TIME(seconds )

函数使用说明: 返回被转化为小时、 分钟和秒数的 seconds 参数值 , 其格式为 'HH:MM:SS' 或 HHMMSS ,具体格式根据该函数是否用在字符串或数字语境中而定

ll) 函数 STR_TO_DATE(str ,format )

函数使用说明:这是 DATE_FORMAT() 函数的倒转。它获取一个字符串 str 和一个格式字符串 format 。若格式字符串包含日期和时间部分,则 STR_TO_DATE() 返回一个 DATETIME 值, 若该字符串只包含日期部分或时间部分,则返回一个 DATE 或 TIME 值。

mm) 函数 SUBDATE(date ,INTERVAL expr type ) SUBDATE(expr ,days )

函数使用说明:当被第二个参数的 INTERVAL 型式调用时 , SUBDATE() 和 DATE_SUB() 的意义相同。对于有关 INTERVAL 参数的信息, 见有关 DATE_ADD() 的讨论。

nn) 函数 SUBTIME(expr ,expr2 )

函数使用说明: SUBTIME() 从 expr 中提取 expr2 ,然后返回结果。 expr 是一个时间或日期时间表达式,而 xpr2 是一个时间表达式。

oo) 函数 SYSDATE()

函数使用说明:返回当前日期和时间值,格式为 'YYYY-MM-DD HH:MM:SS' 或 YYYYMMDDHHMMSS , 具体格式根据函数是否用在字符串或数字语境而定。

pp) 函数 TIME(expr )

函数使用说明:提取一个时间或日期时间表达式的时间部分,并将其以字符串形式返回。

qq) 函数 TIMEDIFF(expr ,expr2 )

函数使用说明: TIMEDIFF() 返回起始时间 expr 和结束时间 expr2 之间的时间。 expr 和 expr2 为时间或 date-and-time表达式, 两个的类型必须一样。

rr) 函数TIMESTAMP(expr ) , TIMESTAMP(expr ,expr2 )

函数使用说明: 对于一个单参数 , 该函数将日期或日期时间表达式expr 作为日期时间值返回 对于两个参数 , 它将时间表达式 expr2 添加到日期或日期时间表达式 expr 中,将 theresult 作为日期时间值返回。

ss) 函数 TIMESTAMPADD(interval ,int_expr ,datetime_expr )

函数使用说明:将整型表达式int_expr 添加到日期或日期时间表达式 datetime_expr 中。 int_expr 的单位被时间间隔参数给定,该参数必须是以下值的其中一个: FRAC_SECOND 、SECOND 、 MINUTE 、 HOUR 、 DAY 、 WEEK 、 MONTH 、 QUARTER 或 YEAR 。可使用所显示的关键词指定Interval 值,或使用SQL_TSI_ 前缀。例如, DAY 或SQL_TSI_DAY 都是正确的

tt) 函数 TIMESTAMPDIFF(interval ,datetime_expr1 ,datetime_expr2 )

函数使用说明:返回日期或日期时间表达式 datetime_expr1 和 datetime_expr2 the 之间的整数差。其结果的单位由 interval 参数给出。 interval 的法定值同 TIMESTAMPADD() 函数说明中所列出的相同。

uu) 函数 TIME_FORMAT(time ,format )

函数使用说明:其使用和 DATE_FORMAT() 函数相同 , 然而 format 字符串可能仅会包含处理小时、分钟和秒的格式说明符。其它说明符产生一个 NULL 值或 0 。

vv) 函数 TIME_TO_SEC(time )

函数使用说明:返回已转化为秒的 time 参数

ww) 函数 TO_DAYS(date )

函数使用说明:给定一个日期 date , 返回一个天数 ( 从年份 0 开始的天数 ) 。

xx) 函数 UNIX_TIMESTAMP(), UNIX_TIMESTAMP(date )

函数使用说明:若无参数调用,则返回一个 Unix timestamp ('1970-01-01 00:00:00' GMT 之后的秒数 ) 作为无符号整数。若用 date 来调用 UNIX_TIMESTAMP() ,它会将参数值以 '1970-01-01 00:00:00' GMT 后的秒数的形式返回。 date 可以是一个 DATE 字符串、一个 DATETIME 字符串、一个 TIMESTAMP 或一个当地时间的 YYMMDD 或 YYYMMDD 格式的数字。

yy) 函数 UTC_DATE, UTC_DATE()

函数使用说明:返回当前 UTC 日期值,其格式为 'YYYY-MM-DD' 或 YYYYMMDD ,具体格式取决于函数是否用在字符串或数字语境中。

zz) 函数 UTC_TIME, UTC_TIME()

函数使用说明:返回当前 UTC 值,其格式为 'HH:MM:SS' 或 HHMMSS ,具体格式根据该函数是否用在字符串或数字语境而定。

aaa) 函数 UTC_TIMESTAMP, UTC_TIMESTAMP()

函数使用说明:返回当前 UTC 日期及时间值,格式为 'YYYY-MM-DD HH:MM:SS' 或 YYYYMMDDHHMMSS ,具体格式根据该函数是否用在字符串或数字语境而定

bbb) 函数 WEEK(date [,mode ])

函数使用说明:该函数返回 date 对应的星期数。 WEEK() 的双参数形式允许你指定该星期是否起始于周日或周一, 以及返回值的范围是否为从 0 到 53 或从 1 到 53 。若 mode 参数被省略,则使用 default_week_format 系统自变量的值。

ccc) 函数 WEEKDAY(date )

函数使用说明:返回 date (0 = 周一 , 1 = 周二 , 6 = 周日 ) 对应的工作日索引 weekday index for

ddd) 函数 WEEKOFYEAR(date )

函数使用说明:将该日期的阳历周以数字形式返回,范围是从 1 到 53 。它是一个兼容度函数,相当于 WEEK(date ,3) 。

eee) 函数 YEAR(date )

函数使用说明:返回 date 对应的年份 , 范围是从 1000 到 9999 。

fff) 函数 YEARWEEK(date ), YEARWEEK(date ,start )

函数使用说明:返回一个日期对应的年或周。 start 参数的工作同 start 参数对 WEEK() 的工作相同。结果中的年份可以和该年的第一周和最后一周对应的日期参数有所不同。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/langs/12175732.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-21
下一篇 2023-05-21

发表评论

登录后才能评论

评论列表(0条)

保存