We use timestamps a lot in web development, whether using Drupal or not. Sometimes during debugging we may want to know what is the actual human readable time for a timestamp (eg. 1279566878). This is easy to achieve in Linux, without writing any PHP code.
date -d@1279566878
Simply use the command in shell and you will see something like Mon Jul 19 12:14:38 PDT 2010, which gives the human readable time for the Unix timestamp 1279566878.
Another thing we'd like to do sometimes is to change the server time and timezone. In Ubuntu, you can type the command
dpkg-reconfigure tzdata
or
tzselect
and then select the timezone you want. Or you can do so by modifying the timezone file /etc/localtime
ln -sf /usr/share/zoneinfo/America/Toronto /etc/localtime
This would set the timezone to America/Toronto.
To change the current server time, you may use the command
date 052018302010.15
which would set the time to May 20, 2010, 18:30:15. The format of the time string is nnddhhmmyyyy.ss where
nn: 2-digit month (01 - 12)
dd: 2-digit day (01 - 31)
hh: 2-digit hour (00 - 23)
mm: 2-digit minute (00 - 59)
yyyy: 4-digit year
ss: 2-digit second (00 - 59)
To display the current server time, just type
date
In case you want to change the timestamp of a file, you may use the touch command
touch -t 201005201830.15 file.txt
which would set the access and modification time of the file file.txt to May 20, 2010, 18:30:15.
For more details of the above commands, please check the corresponding manpages (eg. man date). Some of these commands require sudo privileges.

Post new comment