FreeBSD how to set date

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 yymmddhhmmss

Where,

yy : Year in two digit
mm : Month (1-12)
dd : Day (1-31)
hh : Hours (0..23)
mm : Minutes (0..59)
ss : Seconds (0..61)
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 Set Time Without Modifying The Date

Type the following command to sets the time to 4:30 PM:
# date 1630

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

FreeBSD how to set date