Ring/教程/日期和时间
外观
< Ring
在本章中,我们将学习有关日期和时间函数的信息。
语法
Clock() ---> The number of clock ticks from program start
示例
See "Calculate performance" + nl
t1 = clock()
for x = 1 to 1000000 next
see clock() - t1
我们可以使用 Time() 函数获取系统时间。
示例
See "Time : " + time()
我们可以使用 Date() 函数获取日期。
语法
Date() ---> String represent the date "dd/mm/yyyy"
示例
See "Date : " + date() # Date : 24/05/2015
我们可以使用 TimeList() 函数打印日期和时间信息。
语法
TimeList() ---> List contains the time and date information.
下表列出了这些项目。
====== ===================================
index value
====== ===================================
1 abbreviated weekday name
2 full weekday name
3 abbreviated month name
4 full month name
5 Date & Time
6 Day of the month
7 Hour (24)
8 Hour (12)
9 Day of the year
10 Month of the year
11 Minutes after hour
12 AM or PM
13 Seconds after the hour
14 Week of the year (sun-sat)
15 day of the week
16 date
17 time
18 year of the century
19 year
20 time zone
21 percent sign
====== ===================================
示例
/* Output:
** Sun abbreviated weekday name
** Sunday full weekday name
** May abbreviated month name
** May full month name
** 05/24/15 09:58:38 Date & Time
** 24 Day of the month
** 09 Hour (24)
** 09 Hour (12)
** 144 Day of the year
** 05 Month of the year
** 58 Minutes after hour
** AM AM or PM
** 38 Seconds after the hour
** 21 Week of the year (sun-sat)
** 0 day of the week
** 05/24/15 date
** 09:58:38 time
** 15 year of the century
** 2015 year
** Arab Standard Time time zone
** % percent sign
*/
See TimeList()
示例
See "Day Name : " + TimeList()[2] # Sunday
示例
See "Month Name : " + TimeList()[4] # May
语法
AddDays(cDate,nDays) ---> Date from cDate and after nDays
示例
cDate = date()
see cDate + nl # 24/05/2015
cDate = adddays(cDate,10)
see cDate + nl # 03/06/2015
语法
DiffDays(cDate1,cDate2) ---> number of days (Date1 - Date2)
示例
cDate1 = date()
see cDate1 + nl # 24/05/2015
cDate2 = adddays(cDate1,10)
see cDate2 + nl # 03/06/2015
see "DiffDays = " + diffdays(cDate1,cDate2) + nl # -10
see "DiffDays = " + diffdays(cDate2,cDate1) + nl # 10