Date and time
Die Objekte für Zeit und Datum sind, ähnlich zu den atomaren Objekten, auch unveränderlich. Wird z.B. der Tag eines Datums verändert, so entsteht ein neues Objekt.
Date
Ein Datum-Objekt wird mit dem Objekt-Typ "Date" erzeugt. Dies kann mit oder ohne Argumente erfolgen:
Date # Das heutige Datum
Date() # Identisch mit der Zeile davor
Date( 2020, 3, 1 ) # Objekt für den 1.3.2020
Different formats can be passed with a string
Date( "01.03.2020" )
Date( "2020-03-01" )
Reading individual values:
d = Date
Print d.getDay
Print d.getMonth
Print d.getYear
Since mathematical characters in JM° are also just functions, albeit with a different priority, the following is now possible:
# Gibt das Datum von heute plus 5 Tage aus
Print Date + 5
# Die Variable 'd' bekommt hier das Datum von vorgestern zugewiesen
d = Date - 2
Print d
# Prüft, ob das heutige Datum größer oder gleich dem 1.1.2021 ist
Date >= Date( 2021, 1, 1 )
Of course there are also alphanumeric functions:
# Erzeugt ein neues Objekt von heute plus 3 Monate
Date.addMonth( 3 )
# Erzeugt ein neues Objekt mit heutigem Tag und Monat, allerdings im Jahr 2035
Date.setYear( 2035 )
Additional functions are listed in the reference.
Time
For a time, the object "Time" is used:
# Objekt für die aktuelle Uhrzeit
Time
# Objekt für 12:34:56 Uhr
Time( 12, 34, 56 )
Reading is very direct and simple, similar to Date:
t = Time
t.getHours.print
t.getMinutes.print
t.getSeconds.print
Otherwise a Time object is used similar to Date or DateTime.
Event
To store a time the type DateTime (= date + time) exists:
# Objekt für den aktuellen Zeitpunkt
DateTime
# Zeitpunkt für den 21.01.2020, 11:22:33 Uhr
DateTime( 2020, 1, 21, 11, 22, 33 )
Here it is also possible to get a copy of the date or time:
# Gibt ein Date-Objekt zurück
DateTime.getDate
# Gibt ein Time-Objekt zurück
DateTime.getTime
The reading of the individual values is also done by the respective function:
dt = DateTime
dt.getYear
dt.getMonth
dt.getDay
dt.getHour
dt.getMinutes
dt.getSeconds
Formatted output
To format Date, Time and DateTime we use the function ".format". A format string is used, where different placeholders are replaced.
Info:
Upper case letters stand for date values (day, month, ...), lower case letters for time values (hour, minute, ...)
| Character | Attribute | Length | Example |
|---|---|---|---|
| Y | Year | 4 | 2020 |
| YY | Year | 2 | 20 |
| YYYY | Year | 4 | 2020 |
| M | Month | 1-2 | 1 |
| MM | Month | 2 | 01 |
| D | Tag | 1-2 | 5 |
| DD | Tag | 2 | 05 |
| hh | Hours (24 hrs format) | 2 | 08 |
| h | Hours (24 hrs format) | 1-2 | 8 |
| ii | Hours (12 hr format) | 2 | 11 |
| i | Hours (12 hr format) | 1-2 | 8 |
| mm | Minutes | 2 | 09 |
| m | Minutes | 1-2 | 9 |
| ss | Seconds | 2 | 07 |
| s | Seconds | 1-2 | 7 |
| p | AM/PM | 2 | PM |
To prevent a character from being replaced, we insert a tilde directly in front of it:
Print Date.add( 1 ).format( "~Morgen ist der: DD.MM." )