- Euphoria Tutorial
 - Euphoria - Home
 - Euphoria - Overview
 - Euphoria - Environment
 - Euphoria - Basic Syntax
 - Euphoria - Variables
 - Euphoria - Constants
 - Euphoria - Data Types
 - Euphoria - Operators
 - Euphoria - Branching
 - Euphoria - Loop Types
 - Euphoria - Flow Control
 - Euphoria - Short Circuit
 - Euphoria - Sequences
 - Euphoria - Date & Time
 - Euphoria - Procedures
 - Euphoria - Functions
 - Euphoria - Files I/O
 
- Euphoria Useful Resources
 - Euphoria - Quick Guide
 - Euphoria - Library Routines
 - Euphoria - Useful Resources
 - Euphoria - Discussion
 
Euphoria - 日期和时间
Euphoria 有一个库例程,可以将日期和时间返回给您的程序。
date ()方法
date() 方法返回一个由八个Atomics元素组成的序列值。下面的例子详细解释了它 -
#!/home/euphoria-4.0b2/bin/eui
 
integer curr_year, curr_day, curr_day_of_year, curr_hour, curr_minute, curr_second
sequence system_date, word_week, word_month, notation, 
   curr_day_of_week, curr_month
   word_week = {"Sunday", 
      "Monday", 
      "Tuesday", 
      "Wednesday", 
      "Thursday", 
      "Friday", 
      "Saturday"}
   word_month = {"January", "February", 
      "March", 
      "April", 
      "May", 
      "June", 
      "July", 
      "August", 
      "September", 
      "October", 
      "November", 
      "December"}
-- Get current system date.
system_date = date()
-- Now take individual elements
curr_year = system_date[1] + 1900
curr_month = word_month[system_date[2]]
curr_day = system_date[3]
curr_hour = system_date[4]
curr_minute = system_date[5]
curr_second = system_date[6]
curr_day_of_week = word_week[system_date[7]]
curr_day_of_year = system_date[8]
if curr_hour >= 12 then 
   notation = "p.m."
else 
   notation = "a.m."
end if
if curr_hour > 12 then 
   curr_hour = curr_hour - 12
end if
if curr_hour = 0 then 
   curr_hour = 12
end if
puts(1, "\nHello Euphoria!\n\n")
printf(1, "Today is %s, %s %d, %d.\n", {curr_day_of_week, 
   curr_month, curr_day, curr_year})
printf(1, "The time is %.2d:%.2d:%.2d %s\n", {curr_hour, 
   curr_minute, curr_second, notation})
printf(1, "It is %3d days into the current year.\n", {curr_day_of_year})
这会在您的标准屏幕上产生以下结果 -
Hello Euphoria! Today is Friday, January 22, 2010. The time is 02:54:58 p.m. It is 22 days into the current year.
time ()方法
time() 方法返回一个Atomics值,表示自固定时间点以来经过的秒数。下面的例子详细解释了它 -
#!/home/euphoria-4.0b2/bin/eui
 
constant ITERATIONS = 100000000
integer p
atom t0, t1, loop_overhead
t0 = time()
for i = 1 to ITERATIONS do
   -- time an empty loop
end for
loop_overhead = time() - t0
printf(1, "Loop overhead:%d\n", loop_overhead)
t0 = time()
for i = 1 to ITERATIONS do
    p = power(2, 20)
end for
t1 = (time() - (t0 + loop_overhead))/ITERATIONS
printf(1, "Time (in seconds) for one call to power:%d\n", t1)
这会产生以下结果 -
Loop overhead:1 Time (in seconds) for one call to power:0
日期和时间相关方法
Euphoria 提供了一系列方法来帮助您操作日期和时间。Euphoria 库例程中列出了这些方法。