The localtime
Perl function returns a list of nine elements representing IntelliSurvey's local server time, which is UTC/GMT -8. All localtime
list elements are numeric.
The nine parts of localtime
are:
- seconds: 0-61 (accounts for leap seconds)
- minutes: 0-59
- hours: 0-23
- day of the month: 1-31
- month: 0-11 (January = 0, February = 1, ...)
- year: Years since 1900
- day of the week: 0-6 (Sunday = 0)
- day of the year: 0-365 (accounts for leap years)
- daylight saving time: 1 if in effect, 0 if not
Tip! The month and day of the week are 0-indexed. Add 1 to get typical values (e.g., January = 1, Sunday = 1).
Using 'localtime'
For the following examples, suppose the time captured on a local server is "Fri Oct 30 09:23:32 2020."
Current local server time
NOW. Now type: text invisible: y onload: y cvalue: my $now = localtime; return $now;
Seconds
Using the above example, seconds = 32.
1. Seconds type: text invisible: y onload: y cvalue: ((localtime)[0])
Minutes
2. Minutes type: text invisible: y onload: y cvalue: ((localtime)[1])
Hour of the day
Using the above example, hour = 9.
3. Hour type: text invisible: y onload: y cvalue: ((localtime)[2])
Day of the month
Using the above example, the day of the month = 30.
4. Day of the month type: text invisible: y onload: y cvalue: ((localtime)[3])
Month
The month may be calculated either as being assigned a 0-11 value (default), or a more typical 1-12 value. The month can also be calculated from the month's name, either via open or closed-end responses.
Reminder, the time captured on a local server is "Fri Oct 30 09:23:32 2020."
Default month calculation
Using the above example, month = 9. Here, months are 0-indexed.
5. Month type: text invisible: y onload: y cvalue: ((localtime)[4])
Month + 1
To use 1-12 instead of 0-11 for the month values, add '1' to the month's value. Using the above example, month = 10.
5A. Month + 1 type: text invisible: y onload: y cvalue: ((localtime)[4] + 1)
Month name (Open-ended)
5B. Month - name (open) type: text invisible: y onload: y cvalue:<<END my @months = qw(January February March April May June July August September October November December); my $month = ((localtime)[4]); return $months[$month]; END
Month name (Closed-ended)
The following example adds '1' to the returned value for localtime
.
5C. Month - name (closed) type: radio invisible: y onload: y cvalue: ((localtime)[4] + 1) 1. January 2. February 3. March 4. April 5. May 6. June 7. July 8. August 9. September 10. October 11. November 12. December
Year
The localtime
function is designed to return the number of years since 1900, but can also be used to return the current year by adding '1900' to the response.
Reminder, the time captured on a local server is "Fri Oct 30 09:23:32 2020."
Years since 1900
Using the above example, year = 120.
6. Years since 1900 type: text invisible: y onload: y cvalue: ((localtime)[5])
Current year
By adding '1900' to the calculation, the year = 2020.
6A. Year + 1900 type: text invisible: y onload: y cvalue: ((localtime)[5] + 1900)
Day of the week
Like months, the day of the week is 0-indexed and runs from 0-6, starting with Sunday. The day of the week may also be calculated from both open and closed-end responses as well.
Reminder, the time captured on a local server is "Fri Oct 30 09:23:32 2020."
Default day of the week
Using the above example, the day of the week = 5.
7. Day of the week type: text invisible: y onload: y cvalue: ((localtime)[6])
Day of the week (Open-ended)
7A. Day of the week - name (open) type: text invisible: y onload: y cvalue:<<END my @days = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday); my $dow = ((localtime)[6]); return $days[$dow]; END
Day of the week (Closed-ended)
The following example adds '1' to the returned value for localtime
.
7B. Day of the week - name (closed) type: radio invisible: y onload: y cvalue: ((localtime)[6] + 1) 1. Sunday 2. Monday 3. Tuesday 4. Wednesday 5. Thursday 6. Friday 7. Saturday
Day of the year
Using the above example, for October 30th, 2020, the day of the year = 303.
8. Day of the year type: text invisible: y onload: y cvalue: ((localtime)[7])
Daylight savings time
Using the above example, since daylight savings time was still in effect on October 30th, 2020, daylight savings time = 1.
9. Daylight savings time type: text invisible: y onload: y cvalue: ((localtime)[8])
Comments
0 comments
Please sign in to leave a comment.