Procedure DateTime()

AmigaOS specific forum
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Roxxler.

Hier eine kleine Procedure die das System-Datum und -Zeit liefert.

Here a little Procedure which returns the date and time.


Procedure.b DateTime(format.b)
;
; Das Unterprogramm füllt drei Stringvariablen (wochentag$,datum$,
; uhrzeit$) mit den entsprechenden Daten. Bei einem Fehler
; sind die String$ leer ->"" (Speichermangel etc.). Verwendet werden
; die Dos-Funktionen DateStamp() und DateToStr().
; This procedure fills three string variables (wochentag$,datum$,
; uhrzeit$) with the day of the week, with the date and with the
; time. If there was an error, then the three strings are empty.
; For that the dos.library functions DateStamp() and DateToStr()
; are used.
;
; Parameter: format.b = 0 = tt-mmm-jj DOS-Format
; 1 = jj-mm-tt international format
; 2 = mm-tt-jj USA format
; 3 = tt-mm-jj Kanada format
; Rückgabe : 0 bei einem Fehler - 0 if there was an error
; Returns : -1 alles ok - 1 is all went fine
;
; Voraussetzungen: Die dos.library muß geöffnet sein (OpenDosLibrary_(version)).
; Wird von PureBasic am Programmende wieder geschlossen.
; InitMemoryBank(x) muß ausgeführt werden,
; AllocateMemoryBank(0) wird verwendet.
; Requirements : The dos.library must be open (OpenDosLibrary_(version).
; The lib is closed by PureBasic at the program end.
; The procedure uses AllocateMemoryBank(0), so if you
; use it please add an InitMemoryBank(x) in your
; program.

; we need some memory for the structure Datetime -Speicher für Struktur Datetime reservieren
datetime.l=AllocateMemoryBank(0,26,#MEMF_FAST|#MEMF_CLEAR)
If datetime0 ; wenn Speicher da - blah blah
result.l=0
Shared wochentag$,datum$,uhrzeit$
wochentag$=" " ; die Strings müssen 16 Byte lang sein - we need 16 bytes long strings
datum$=" "
uhrzeit$=" "
PokeB(datetime+12,format) ; format eintragen - fill in the format
PokeB(datetime+13,0) ; Datum ausgeben (nicht "Heute" etc.) - we need the date (not "Today" etc.)
PokeL(datetime+14,@wochentag$) ; Zeiger auf 16 Byte lange Strings - pointers to the empty strings
PokeL(datetime+18,@datum$)
PokeL(datetime+22,@uhrzeit$)

DateStamp_(datetime) ; Funktion DateStamp(S) aufrufen - calling DateStamp()
result=DateToStr_(datetime) ; Funktion DateToStr(DOS) aufrufen - and now calling DateToStr()
If result0 ; wenn kein Fehler(=0) result auf TRUE setzen - no error -> result = TRUE
result=-1
EndIf
FreeMemoryBank(0)
Else
wochentag$=""
datum$=""
uhrzeit$=""
result=0
EndIf
ProcedureReturn result
EndProcedure

InitMemoryBank(0)
DosBase.l=OpenDosLibrary_(36)
If DosBase0
erfolg=DateTime(0)
PrintNumberN(erfolg)
PrintN(wochentag$)
PrintN(datum$)
PrintN(uhrzeit$)
Else
PrintN("Cannot open dos.library")
EndIf
End


Greetings ..
Roxxler
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by El_Choni.

This is for PB Amiga, isn't it? Great to see some Amiga examples.

Have a nice day,

El_Choni
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Roxxler.
This is for PB Amiga, isn't it? Great to see some Amiga examples.

Have a nice day,

El_Choni
Hi,
yes it is for the Amiga version of PureBasic. I do my best,
but still lerning :)
Greetings ..
Roxxler
Post Reply