This can be done with several caveats:
@now will return the current time (at render) in the local timezone for the user
toLocaleTimeString may return different formats depending on the user's browser locale
- The expression below is assuming time in a 12 hour clock with the hour first separated with a colon from the next value. If the localetimestring is different the expression will need to be adjusted
- If the list is open at 4:59pm it will be green and won't turn red at 5pm until the list item is either updated or the view is refreshed
- There is no lower bounds. If the time is AM it will be green, otherwise it checks the hour is earlier than 5
- If you want to include exactly 5:00pm in the green condition (but not 5:01pm) you'll have to extend the expression to look at the minutes as well
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
"elmType": "div",
"txtContent": "@currentField",
"attributes": {
"class": "='ms-fontColor-white ' + if(indexOf(toLocaleTimeString(@now), 'AM') > -1 || Number(substring(toLocaleTimeString(@now),0,indexOf(toLocaleTimeString(@now),':'))) < 4, 'ms-bgColor-green', 'ms-bgColor-red')"
}
}
In the above I'm using the standard Microsoft red and green classes for background color (with white text). If you'd rather apply this to background-color with a custom color value you can just take the expression starting with the if and swap out the class names with your color values.