That's what the desktop/mobile app does for generating the TOTP code that's using the TOTP secrets on the Yubikey.
I'm not sure if a Yubikey's simplest mode as a HID device can read the device's wall clock it's attached to without additional drivers?