What OS? You were asking about "elf", so maybe 32-bit Linux? Are you willing to use C library routines? Show us how far you can get with this by yourself...
I have a program to display (not set) time and date (32-bit Linux), but it's broken! I thought it was working fine, but I tried it on New Year's Eve and it informed me that it was "Jan 00 2015". Oops! I think I see what's wrong with it, but before I could fix it, midnight had passed and it went to "Jan 01" as expected. I may have to wait until next New Year's Eve to fix it...
Best,
Frank