euphoria has a library routine that returns the date and time to your program.
the date() method
the date() method returns a sequence value composed of eight atom elements. the following example explains it in detail −
#!/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})
this produces the following result on your standard screen −
hello euphoria! today is friday, january 22, 2010. the time is 02:54:58 p.m. it is 22 days into the current year.
the time() method
the time() method returns an atom value, representing the number of seconds elapsed since a fixed point in time. the following example explains it in detail −
#!/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)
this produces the following result −
loop overhead:1 time (in seconds) for one call to power:0
date & time related methods
euphoria provides a list of methods which helps you in manipulating date and time. these methods are listed in euphoria library routines.