Is there a way to get a DateTime object from a unix timestamp and hour offset? I want to be able to print a formatted string, for example Wed Apr 02 17:15:06 2014.

I have:

  1. A unix timestamp: 1396451852.
  2. An offset from my hour zone, +1 hour.

Note: I get the timestamp from an internet service and want to make the conversion in the Arduino.

  • To clarify: You have a unix time-stamp on your arduino and you want to make the conversion there? Could the supplier of the timestamp instead provide the formatted string?
    – JRobert
    Commented Apr 2, 2014 at 15:23
  • Yes! i get this unix time-stamp from internet.
    – lasote
    Commented Apr 2, 2014 at 15:24

2 Answers 2


The seconds since (UNIX) epoch relies on a database.

New editions of the database and code are published as changes warrant, usually several times per year.

Your options can:

  • Reduce the timezone database to the timezone you are actually interested in;
  • Don't forget about daylight savings time for you specific timezone;
  • The leap years are well known too and reasonably easy to program;
  • The leap seconds are decided upon usually only couple months before they are introduced and therefore cannot be accounted for in an algorithm.


  • So can you convert epoch to a time/date format? Yes.
  • Will it be accurate? It'll drift away over time (months or years)


If you retrieve epoch from an Internet service, why not use (another?) webserver that has the full timezone database available to convert it to accurate date/time, or 'synchronize' against every once in a while?

  • +1 For letting me know that leap seconds exist AND for the great answer.
    – Ricardo
    Commented Apr 4, 2014 at 17:16

The Arduino Time Library looks like it can do it. Or have a look at the strftime() function from unix and unix-oid environments. There is source to strftime() here. It's pretty large but you can probably cut it down considerably to just the format parts you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.