Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
$ date 042612492005
$ hwclock -w

The code above shows how to set the system time, but how's the timestamp string generated in the first place?

share|improve this question

migrated from stackoverflow.com Apr 12 '11 at 4:24

This question came from our site for professional and enthusiast programmers.

I'm not sure what your question is exactly? Is it... how is the timestamp (042612492005) generated? – gabe. Apr 12 '11 at 15:48

The date format is:


So your above example can be read as:

12:49:00 04-26-2005

By the way, that first line sets the system time while the second line sets the hardware clock. See this explanation.

share|improve this answer
Thank you for that link. :) – boehj Apr 12 '11 at 5:47

More the likely, you type it in. In man date you can see it take the format [MMDDhhmm[[CC]YY][.ss]]

So the above would read 12:49 PM April 26, 2005

Right now , in Texas it is 041122292011 (10:29 PM April 11, 2011)

share|improve this answer

On linux, the timestamp is generated by the time() function.

$ man 2 time
TIME(2)                    Linux Programmer's Manual                   TIME(2)

       time - get time in seconds


       time_t time(time_t *t);

       time()  returns  the  time  since  the  Epoch (00:00:00 UTC, January 1,
       1970), measured in seconds.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.