AWK, 47 bytes
$0=strftime("%j",r=systime(),1)*(q=86400)+r%q-q
Try it online!
I wasn't sure if the seconds into the year should start from midnight Jan 1 in the local timezone or in UTC. This version works for UTC.
It figures out the julian date (the number of days into the year), converts that to seconds then adds in the fractional day's worth of seconds.
strftime("%j",r=systime(),1)
Gets the julian date, and stores the UNIX epoch in variable r
in the process. It add a 3rd parameter on strftime
to get the time in UTC.
*(q=86400)
Converts the days to seconds and saves the constant "seconds per day" in for use later.
+r%q
Adds in the seconds corresponding to the HH:MM:SS
offset from midnight UTC using modulo math.
-q
And this is annoying 2 characters I couldn't figure out how to drop... Since julian days start with 1, the %j
include the current day so we have to subtract a full day.
$0=
Finally, assigning the result to $0
means the whole expression is actually a condition, which is always truthy except for at exactly midnight on Jan 1st, so the value is printed.
If an offset in seconds from local time is acceptable, this more straightforward, and slightly shorter code would work.
$0=systime()-mktime(strftime("%Y 1 1 0 0 0"))
That one just subtracts the UNIX epoch for Jan 1st at mightnight of the current year from the current epoch time.