A Spla program can handle date and time in several ways. Converting between date formats is a common chore for computers. Spla's time and calendar modules help track dates and times.
Time intervals are floating-point numbers in units of seconds. Particular instants in time are expressed in seconds since 12:00am, January 1, 1970
Spla also provides functions for working with times, and for converting between representations. The function time.getTime<> returns the current system time in ticks since 12:00am, January 1, 1970
Time time; int tm= time.getTime<> << "Number of ticks since 12:00am, January 1, 1970:"+ ticks;
This would produce a result something as follows −
Number of ticks since 12:00am, January 1, 1970: 1455508609.34375
Date arithmetic is easy to do with ticks. However, dates before the epoch cannot be represented in this form. Dates in the far future also cannot be represented this way - the cutoff point is sometime in 2038 for UNIX and Windows.
Many of the Spla's time functions handle time as a combination of 9 numbers, as shown below −
| Index | Field | Values |
|---|---|---|
| 0 | 4-digit year | 2016 |
| 1 | Month | 1 to 12 |
| 2 | Day | 1 to 31 |
| 3 | Hour | 0 to 23 |
| 4 | Minute | 0 to 59 |
| 5 | Second | 0 to 61 <60 or 61 are leap-seconds> |
| 6 | Day of Week | 0 to 6 <0 is Monday> |
| 7 | Day of year | 1 to 366 |
| 8 | Daylight savings | -1, 0, 1, -1 means library determines DST |
For Example −
Time time; <<time;
This would produce a result as follows −
2019-05-10 00:06:44
You can format any time as per your requirement, but a simple method to get time in a readable format is format<> −
Time time; strlocaltime = time.format<>; <<'Local current time :', localtime;
This would produce the following result −
Local current time : 2019-05-10 00:06:44