About Linux FAQ

Browse More FAQs:

FreeBSD: Set date time and timezone

Posted by Vivek on Friday February 10, 06 @12:29 am

Q. How do I setup date and time in FreeBSD operating system at a shell prompt?

A. Under FreeBSD you can use date command to display or set date and time. The date command displays the date and time read from the kernel clock. If you just type date command without any options (read as without arguments) the date command display the current date and time only.

Please note that if you are looking Linux specific date command faq, please read this FAQ.

FreeBSD Display todays date

Type date command as follows, to display todays date and time:
$ date
Output:

Thu Feb  9 23:43:19 IST 2006

FreeBSD set date and time

Only the superuser or root user may set the date under FreeBSD. General format of date command is as follows:
date yymmddhhss
Where,

  • yy : Year in two digit
  • mm : Month (1-12)
  • dd : Day (1-31)
  • hh : Hours (0..23)
  • ss : Seconds

For example following command set date to 12-Jan-2004, 4:27 PM (remember you must be a root user to set date and time)
# date 0401121627

Output:

Mon Jan 12 16:27:00 IST 2004

FreeBSD Setup Timezone

To setup corrct timezone you need to copy your timezone file from /usr/share/zoneinfo directory to /etc/localtime file. Just goto directory:
# cd /usr/share/zoneinfo

Use ls -l command to find out your zonefile.
# ls -l

For example I am in Asia/Culcatta (IST time zone) so I need to copy file as follows:
# cp /usr/share/zoneinfo/Asia/Calcutta /etc/localtime

date command and use of environment variable

You can also use TZ environment variable to display date and time according to your timezone. For example to display the current time in California you need to export TZ as follows (assuming that you are using bash shell):
# date

Output:

Fri Feb 10 00:39:59 IST 2006

Now use TZ variable:
# export TZ=America/Los_Angeles
# date

Output:

Thu Feb 9 11:10:08 PST 2006

See also:

Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

Related Linux / UNIX FAQ:

Discussion on This FAQ

  1. JaY Says:

    Good Site.. Keep Up the Good Work. Just wanted to point out that you may confuse a noob by showing this example since you put mm at the end of your sample but in your key you list ss as the second. Probly should tell them its the minute.. Just a FYI I know how it is.. nix people jot things down so fast that they don’t even notice it..

    date yymmddhhmm
    Where,

    yy : Year in two digit
    mm : Month (1-12)
    dd : Day (1-31)
    hh : Hours (0..23)
    ss : Seconds

    For the new person that didn’t know at the end of the string its the minute .. even though it looks like it asks for the month in this example.

    JaY

  2. nixcraft Says:

    JaY,

    It was typo. The correct syntax is as follows (updated):
    date yymmddhhss

    Appreciate your post.

  3. Gooofy Says:

    That conflicts with the format posted here
    http://www.linuxdevcenter.com/linux/cmd/cmd.csp?path=d/date

    date mmddhhmmyy

  4. nixcraft Says:

    Gooofy,

    This FAQ is about FreeBSD and not about Linux. So the command format is correct and it only works with FreeBSD. Linux specific information:
    http://www.cyberciti.biz/faq/howto-set-date-time-from-linux-command-prompt/

  5. Paul Says:

    Your site was really of much help to me. Thanks a million.

  6. Charles Says:

    I did major screwup on production server wanting to paste a date change command to a test machine.

    just be careful when you test daylight savings, and make sure you do it on a “test” machine not on your NTP server :)

  7. Otuyelu Says:

    While on a FreeBSD system tried using the Linux format to no avail, before running to google where i found your post.

    Thanks for posting, a real help

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Please do not use the comment form to ask for help / question. Ask your question on the excellent Linux tech support forum. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , , , , , , ~ Last updated on: September 13, 2007

Copyright © 2006-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.