日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

四、日期、时间函数

發(fā)布時間:2023/12/20 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 四、日期、时间函数 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

四、日期、時間函數(shù)

1、Day()

功? 能:得到日期型數(shù)據(jù)中的號數(shù)(1到31之間的整數(shù)值)。

語? 法:Day ( date )

參? 數(shù):date:要得到號數(shù)的日期值。

返回值:Integer。函數(shù)執(zhí)行成功時返回號數(shù)(1到31之間的整數(shù)值)。如果date參數(shù)的值為NULL,則Day()函數(shù)返回NULL。

示? 例:These statements extract the day (31) from the date literal 1994-01-31 and set li_day_portion to that value:

integer li_day_portion

li_day_portion = Day(1994-01-31)

?

These statements check to be sure the date in sle_date is valid, and if so set li_day_portion to the day in the sle_date:

integer li_day_portion

IF IsDate(sle_date.Text) THEN

??? li_day_portion = Day(Date(sle_date.Text))

ELSE

??? MessageBox("Error", "This date is invalid: " + sle_date.Text)

END IF

?

2、DayName()

功? 能:得到指定日期是一周中的星期幾(例如,Sunday, Monday...)。

語? 法:DayName ( date )

參? 數(shù):date:date類型值或變量。

返回值:String。函數(shù)執(zhí)行成功時返回指定日期的星期表示(例如,Sunday, Monday...)。如果date參數(shù)的值為NULL,則DayName()函數(shù)返回NULL。

示? 例:These statements evaluate the date literal 1993-07-04 and set day_name to Sunday:

string day_name

day_name = DayName(1993-07-04)

?

These statements check to be sure the date in sle_date is valid, and if so set day_name to the day in sle_date:

string day_name

IF IsDate(sle_date.Text) THEN

??? day_name = DayName(Date(sle_date.Text))

ELSE

??? MessageBox("Error", "This date is invalid: " + sle_date.Text)

END IF

?

3、DayNumber()

功? 能:得到日期型數(shù)據(jù)是一星期中的第幾天(用1到7之間的整數(shù)表示,星期天為1,星期一為2,...)。

語? 法:DayNumber ( date )

參? 數(shù):date:date類型值或變量。

返回值:Integer。函數(shù)執(zhí)行成功時返回指定日期是一星期中的第幾天(用1~7表示,星期天為1,星期一為2,...)。如果date參數(shù)的值為NULL,則DayNumber()函數(shù)返回NULL。

示? 例:These statements evaluate the date literal 1990-01-31 and set day_nbr to 4 (January 31, 1990, was a Wednesday):

integer day_nbr

day_nbr = DayNumber(1990-01-31)

?

These statements check to be sure the date in sle_date is valid, and if so set day_nbr to the number of the day in the sle_date:

integer day_nbr

IF IsDate(sle_date.Text) THEN

??? day_nbr = DayNumber(Date(sle_date.Text))

ELSE

??? MessageBox("Error", "This date is invalid: " + sle_date.Text)

END IF

?

4、DaysAfter()

功? 能:得到兩個日期間的天數(shù)。

語? 法:DaysAfter ( date1, date2 )

參? 數(shù):date1:date類型,指定起始日期;

date2:date類型,指定終止日期。

返回值:Long。函數(shù)執(zhí)行成功時得到兩個日期之間的天數(shù)。如果date2的日期在date1的前面,那么DaysAfter()函數(shù)返回負(fù)值。如果任何參數(shù)的值為NULL,則DaysAfter()函數(shù)返回NULL。

示? 例:1、This statement returns 4:

DaysAfter(2002-12-20, 2002-12-24)

2、This statement returns -4:

DaysAfter(2002-12-24, 2002-12-20)

3、This statement returns 0:

DaysAfter(2003-12-24, 2003-12-24)

4、This statement returns 5:

DaysAfter(2003-12-29, 2004-01-03)

5、If you declare date1 and date2 date variables and assign February 16, 2003, to date1 and April 28, 2003, to date2 as follows:

date date1, date2

date1 = 2003-02-16

date2 = 2003-04-28

then each of the following statements returns 71:

DaysAfter(date1, date2)

DaysAfter(2003-02-16, date2)

DaysAfter(date1, 2003-04-28)

DaysAfter(2003-02-16, 2003-04-28)

?

5、Hour()

功? 能:得到時間值中的小時,采用24小時制。

語? 法:Hour ( time )

參? 數(shù):time:time類型的值。

返回值:Integer。函數(shù)執(zhí)行成功時得到time參數(shù)中的小時(00到23之間)。如果time參數(shù)的值為NULL,則Hour()函數(shù)返回NULL。

示? 例:1、This statement returns the current hour:

Hour(Now())

2、This statement returns 19:

Hour(19:01:31)

?

6、Minute()

功? 能:得到時間值中的分鐘,有效值在00~59之間。

語? 法:Minute ( time )

參? 數(shù):time:time類型的值。

返回值Integer。函數(shù)執(zhí)行成功時得到time參數(shù)中的分鐘(00到59之間)。如果time參數(shù)的值為NULL,則Minute()函數(shù)返回NULL。

示? 例:This statement returns 1:

Minute(19:01:31)

?

7、Month()

功? 能:得到日期值中的月份,有效值在1~12之間。

語? 法:Month ( date )

參? 數(shù):date:date類型的值。

返回值:Integer。函數(shù)執(zhí)行成功時得到date參數(shù)中的月份(1到12之間)。如果date參數(shù)的值為NULL,則Month()函數(shù)返回NULL。

示? 例:This statement returns 1:

Month(1994-01-31)

?

These statements store in start_month the month entered in the SingleLineEdit sle_start_date:

integer start_month

start_month = Month(date(sle_start_date.Text))

?

8、Now()

功? 能:得到客戶機(jī)的當(dāng)前系統(tǒng)時間,返回值為Time類型。

語? 法:Now()

返回值:Time。該函數(shù)返回客戶機(jī)的當(dāng)前系統(tǒng)時間。

示? 例:This statement returns the current system time.

Now()

?

This example displays the current time in the StaticText st_time. It keeps the time up-to-date by setting a timer that triggers a Timer event every 60 seconds. Code in the window's Open event displays the initial time and starts the timer. Code in the Timer event displays the time again.

The following code appears in the window's Open event script:

st_time.Text = String(Now(), "hh:mm")

Timer(60)

?

A single line in the Timer event script refreshes the time display:

st_time.Text = String(Now(), "hh:mm")

?

9、RelativeDate()

功? 能:得到指定日期前多少天或后多少天的日期。

語? 法:RelativeDate(date,n)

參? 數(shù):date:Date類型,指定基準(zhǔn)日期

n:integer類型,指定天數(shù)。

返回值:Date。當(dāng)n的值大于0時返回參數(shù)date指定日期后第n天的日期;當(dāng)n的值小于0時返回參數(shù)date指定日期前第n天的日期。如果任何參數(shù)的值為NULL,則RelativeDate()函數(shù)返回NULL。

示? 例:This statement returns 1990-02-10:

RelativeDate(1990-01-31, 10)

?

This statement returns 1990-01-21:

RelativeDate(1990-01-31,? - 10)

?

10、RelativeTime()

功? 能:得到指定時間前多少秒或后多少秒的時間,采用24小時制。

語? 法:RelativeTime ( time, n )

參? 數(shù):time:time類型,指定基準(zhǔn)時間

n:long類型,指定秒數(shù)。

返回值:Time。當(dāng)n的值大于0時返回參數(shù)time指定時間后第n秒的時間;當(dāng)n的值小于0時返回參數(shù)time指定時間前第n秒的時間。如果任何參數(shù)的值為NULL,則RelativeTime()函數(shù)返回NULL。

示? 例:This statement returns 19:01:41:

RelativeTime(19:01:31, 10)

This statement returns 19:01:21:

RelativeTime(19:01:31,? - 10)

?

11、Second()

功? 能:得到時間值中的秒,有效值在00~59之間。

語? 法:Second ( time )

參? 數(shù):time:time類型的值。

返回值:Integer。函數(shù)執(zhí)行成功時得到time參數(shù)中的秒(00到59之間)。如果time參數(shù)的值為NULL,則Second()函數(shù)返回NULL。

示? 例:This statement returns 31:

Second(19:01:31)

?

11、Second()

功? 能:得到時間值中的秒,有效值在00~59之間。

語? 法:Second ( time )

參? 數(shù):time:time類型的值。

返回值:Integer。函數(shù)執(zhí)行成功時得到time參數(shù)中的秒(00到59之間)。如果time參數(shù)的值為NULL,則Second()函數(shù)返回NULL。

示? 例:This statement returns 31:

Second(19:01:31)

?

12、SecondsAfter()

功? 能:得到兩個時間之間的秒數(shù)。讓前一個時間比后一個時間早時,該函數(shù)的值為正數(shù);兩者相等時為零;反之則為負(fù)數(shù)。

語? 法:SecondsAfter ( time1 , time2 )

參? 數(shù):time1:time類型的值,要度量的時間間隔的起始值;

time2:time類型的值,要度量的時間間隔的結(jié)束值;

返回值:Long。函數(shù)執(zhí)行成功時返回起始時間和結(jié)束時間之間的秒數(shù)。如果任何參數(shù)的值為NULL,則函數(shù)返回NULL。

示? 例:This statement returns 15:

SecondsAfter(21:15:30, 21:15:45)

?

This statement returns -15:

SecondsAfter(21:15:45, 21:15:30)

?

This statement returns 0:

SecondsAfter(21:15:45, 21:15:45)

?

If you declare start_time and end_time time variables and assign 19:02:16 to start_time and 19:02:28 to end_time as shown below:

time start_time, end_time

start_time = 19:02:16

end_time = 19:02:28

then each of these statements returns 12:

SecondsAfter(start_time, end_time)

SecondsAfter(19:02:16, end_time)

SecondsAfter(start_time, 19:02:28)

SecondsAfter(19:02:16, 19:02:28)

?

13、Today()

功? 能:得到當(dāng)前系統(tǒng)日期,在某些情況下,同時得到當(dāng)前系統(tǒng)時間。

語? 法:Today()

返回值:Date。該函數(shù)返回當(dāng)前系統(tǒng)日期。

用? 法:單獨(dú)調(diào)用Today()函數(shù)時,該函數(shù)總是返回當(dāng)前系統(tǒng)日期,但是,雖然Today()函數(shù)的返回值類型為Date,在該函數(shù)用做某些函數(shù)的參數(shù)、而該參數(shù)要求DateTime類型的值時,Today()函數(shù)也能夠在返回當(dāng)前系統(tǒng)日期的同時返回當(dāng)前系統(tǒng)時間。

再如,Today()函數(shù)作為數(shù)據(jù)窗口控件SetItem()函數(shù)的參數(shù),該函數(shù)參數(shù)中指定的數(shù)據(jù)窗口列的數(shù)據(jù)類型為DateTime,那么當(dāng)前系統(tǒng)日期和時間將同時設(shè)置到數(shù)據(jù)窗口指定項中。

示? 例:This statement returns the current system date:

Today()

?

This statement executes some statements when the current system date is before April 15, 2003:

IF Today() < 2003-04-15 THEN ...

?

This statement displays the current date in the StaticText st_date in the corner of a window:

st_date.Text = String(Today(), "m/d/yy")

?

This statement displays the current date and time in the StaticText st_date:

st_date.Text = String(Today(), "m/d/yy hh:mm")

?

14、Year()

功? 能:得到日期值中的年度(有效取值1000到3000)。

語? 法:Year(date)

參? 數(shù):date:date類型的值。

返回值:Integer。函數(shù)執(zhí)行成功時得到date參數(shù)中的年份(采用四位數(shù)字),發(fā)生錯誤時返回1900,如果date參數(shù)的值為NULL,則Year()函數(shù)返回NULL。

用? 法:當(dāng)應(yīng)用程序把有兩位數(shù)字表示年份的字符串轉(zhuǎn)換成日期時,PowerBuilder根據(jù)下述規(guī)則選擇世紀(jì):如果年份值在00到49之間,PowerBuilder將年份中的世紀(jì)(前兩位數(shù)字)當(dāng)作20;如果年份值在50到99之間,PowerBuilder將年份中的世紀(jì)(前兩位數(shù)字)當(dāng)作19。比如,字符串"20-10-25"被PowerBuilder轉(zhuǎn)換為2020-10-25;字符串"98-10-25"被PowerBuilder轉(zhuǎn)換為1998-10-25。因此,如果應(yīng)用程序中需要指定1950年之前的日期,應(yīng)該使用四位數(shù)字表示年份,以避免引起歧義。PowerBuilder能夠處理的年份從1000到3000之間。

示? 例:This statement returns 1995:

Year(1995-01-31)

總結(jié)

以上是生活随笔為你收集整理的四、日期、时间函数的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。