secondOf() : Extract Second from DateTime
On this page
Summary
Extract the second component from a datetime value as a number (0-59).
Signature
secondOf(datetime)
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
datetime |
DateTime | Yes | The datetime to extract the second from |
Returns
Type: Number (Integer)
The second as a number from 0 to 59.
Examples
Display Second
Data:
doc.Params["model"] = new {
time = new DateTime(2024, 3, 15, 14, 30, 45)
};
Output:
<p>Second: 45</p>
Precise Time Display
Data:
doc.Params["model"] = new {
time = new DateTime(2024, 3, 15, 9, 5, 3)
};
Output:
<p>Time: 9:05:03</p>
Timestamp Validation
Data:
doc.Params["model"] = new {
events = new[] {
new { timestamp = new DateTime(2024, 3, 15, 10, 30, 0) },
new { timestamp = new DateTime(2024, 3, 15, 10, 32, 15) },
new { timestamp = new DateTime(2024, 3, 15, 10, 35, 0) }
}
};
Output:
<p>10:30:00 AM (Rounded)</p>
<p>10:32:15 AM</p>
<p>10:35:00 AM (Rounded)</p>
Performance Timing
Data:
doc.Params["model"] = new {
startTime = new DateTime(2024, 3, 15, 10, 0, 12),
endTime = new DateTime(2024, 3, 15, 10, 0, 47)
};
Output:
<h3>Request Processing Time</h3>
<p>Start: 10:00:12</p>
<p>End: 10:00:47</p>
<p>Seconds: 35</p>
Synchronization Check
Data:
doc.Params["model"] = new {
lastSync = new DateTime(2024, 3, 15, 10, 30, 3)
};
Output:
<p>Sync Status: Recently synced</p>
Notes
- Returns 0-59
- Date, hour, and minute components are ignored
- For full time formatting, use
format()function - Useful for:
- Precise timestamp display
- Performance timing
- Synchronization tracking
- High-precision time calculations
- Combine with
hourOf()andminuteOf()for complete time parsing - Use
millisecondOf()for sub-second precision - Use
padLeft()for zero-padded display (e.g., “05” instead of “5”)