time
- The default format of [time] is HH:MM:SS (24-hour clock), time format can be changed in WebDNA Preference Settings
- Putting [time] in a template displays the current time as defined by the clock of the web server
- Override the default [time] format preference on a case-by-case basis by specifying a format inside the tag, as shown below
Parameters
Parameter | Description |
---|---|
format | The required format of the date |
Time Formats - case sensitive:
Example WebDNA code:
Mix time & date WebDNA code:
Calculations on time are made simple using WebDNA. To calculate the time difference between 16:04:23 and 09:34:46 on the same day, use the following example. The result will be the number of seconds that have elapsed, there are 86,400 seconds in a day. Using [format] will convert seconds into hours, minutes and seconds. This can be done using the expanded method of formatting the result, or the newer 'shorthand method of incorporating the formatting into the [math] tag.
Example WebDNA code:
Converting a time calculation back to hours, minutes and seconds. Combining the 'time formats' in the table above with 'seconds_to_time' provides the ability to format the result in a desired form, in this case only hours and minutes are displayed.
Example WebDNA code:
Removing leading zeros.
On Linux and Apple platform servers, the leading zero can be removed using a hyphen "-" after "%"
Example WebDNA code:
Format | Description |
---|---|
%H | Hour "00-24" |
%-H | Hour "1-12" (no leading 0 when adding - before the capital h) |
%#H | Hour "1-12" (no leading 0 when adding # before the capital h) |
%I | Hour "01-12" (capital i) |
%l | Hour "1-12" (no leading 0 when using a lowercase L) |
%M | Minute "00-59" |
%S | Seconds "00-59" |
%p | Am or PM |
%X | Time as "14:01:12" |
%c | Date and time "Wed Jan 25 18:24:21 2022" |
%s | Unix time stamp "1630208860", the number of seconds since January 1st, 1970 00:00:00 UTC |
%z | Offset of server ie the difference in hours from GMT/UTC eg: +1100 |
%Z | Time zone of the server eg: AEDT, this reads as Australian Eastern Dalylight Time |
Example WebDNA code:
Formats in the [time] tag can be combined with ordinary characters,
such as the comma, slash and space
[time] returns: 14:32:37
[time %I:%M %p] returns: 02:30 PM
[time %l:%M %p] returns: 2:30 PM
[time %H:%M %p] returns: 14:30 PM
[time %H:%M:%S] returns: 14:30:45
[time format=%H:%M:%S] returns: 14:30:45
The leading zero can be eliminated on Linux & Apple servers using lowercase L
[time %l:%M %p] returns: 2:08 PM
or a hyphen "-" after the "%"
[time %-I:%M %p] returns: 2:08 PM
[time %-I:%-M %p] returns: 2:8 PM
Mix time & date WebDNA code:
[time] and [date] tags can be mixed by using the "%" formatting switches
[time %A, %I:%M %p] returns: Friday, 2:30 PM
[date %A, %I:%M %p] returns: Friday, 2:30 PM
Calculations on time are made simple using WebDNA. To calculate the time difference between 16:04:23 and 09:34:46 on the same day, use the following example. The result will be the number of seconds that have elapsed, there are 86,400 seconds in a day. Using [format] will convert seconds into hours, minutes and seconds. This can be done using the expanded method of formatting the result, or the newer 'shorthand method of incorporating the formatting into the [math] tag.
Example WebDNA code:
[math]{16:04:23}-{09:34:46}[/math]
[format seconds_to_time][math]{16:04:23}-{09:34:46}[/math][/format]
[math seconds_to_time]{16:04:23}-{09:34:46}[/math]
Converting a time calculation back to hours, minutes and seconds. Combining the 'time formats' in the table above with 'seconds_to_time' provides the ability to format the result in a desired form, in this case only hours and minutes are displayed.
Example WebDNA code:
[math seconds_to_time %H:%M]{16:04:23}-{09:34:46}[/math]
Removing leading zeros.
On Linux and Apple platform servers, the leading zero can be removed using a hyphen "-" after "%"
Example WebDNA code:
[math seconds_to_time %I:%M:%S %p]{09:04:06}[/math] << returns 09:04:06 AM
[math seconds_to_time %-I:%M:%S %p]{09:04:06}[/math] << returns 9:04:06 AM
[math seconds_to_time %-I:%M:%S %p]{12:45:11}[/math] << returns 12:45:11 PM
[math seconds_to_time %-I:%-M:%-S %p]{09:04:06}[/math] << returns 9:4:6 AM