13.13Time & date. 4tH 4tH Forth compiler
Anuncio
Anuncio
CHAPTER 13. SPECIAL LIBRARIES
13.13
Time & date
219
There is also an internal word in 4tH that will tell you what time and what date it is. With a little trouble ;). That word is called ’TIME’ and it will tell you how many seconds have gone since January 1st, 1970. That is the POSIX time format, which probably is of little use to you. However, combined with the appropriate library you can find out how late it is right now:
[needs lib/time.4th] now ." hours:" . ." minutes:" . ." seconds:" . cr
Note that it doesn’t know about daylight-saving! It does know about timezones, which may be neccesary on some systems. You can determine your timezone by looking at an email message from a local friend. It will probably say somewhere:
Date: Mon, 25 Feb 2002 22:28:59 +0100 (CET)
The ’+0100’ means that you’re in timezone CET, which is one hour later than GMT. If it said:
Date: Sun, 16 Dec 2001 02:19:40 -0800 (PST)
This indicates that you’re in timezone PST, which is eight hours earlier than GMT. In that case ’tz’ would be:
-8 3600 * +constant tz \ Pacific Standard Time
If you need it, define it accordingly before the inclusion of time.4th. There are also several words that will allow you to convert any POSIX time: time posix>time . . . cr
Which will return the number of seconds (TOS), the number of minutes and the number of hours. ”POSIX>JDAY” will convert any POSIX time to a Julian day. The day of the week is another thing you can easily calculate:
[needs lib/time.4th]
: Weekdays dup 0 = if drop s" Monday" dup 1 = if drop s" Tuesday" exit then exit then dup 2 = if drop s" Wednesday" exit then dup 3 = if drop s" Thursday" exit then dup 4 = if drop s" Friday" exit then dup 5 = if drop s" Saturday" exit then dup 6 = if drop s" Sunday" exit then
; today weekday Weekdays type cr
By the way, didn’t you hate the way we had to define "Weekdays"? Ugly, isn’t it? Well, there is a better way to do it. You’ll learn that in the next chapter (see section 12.15)! You can also print the full date:
Descargar
Anuncio