Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
TetraWiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Linux 101 hacks
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
='''Chapter 2: Date Manipulation'''= =='''Hack 7. Set System Date and Time'''== To change the system date use: <nowiki># </nowiki>date {mmddhhmiyyyy.ss} o mm – Month o dd – Date o hh – 24 hour format o mi – Minutes o yyyy – Year o ss – seconds For example, to set system date to Jan 31<sup>st</sup> 2008, 10:19 p.m, 53 seconds <nowiki># </nowiki>date 013122192009.53 You can also change system date using set argument as shown below. # date 013122192009.53 # date +%Y%m%d -s "20090131" # date -s "01/31/2009 22:19:53" # date -s "31 JAN 2009 22:19:53" # date set="31 JAN 2009 22:19:53" To set the time only: <nowiki># </nowiki>date +%T -s "22:19:53" <nowiki># </nowiki>date +%T%p -s "10:19:53PM" =='''Hack 8. Set Hardware Date and Time'''== Before setting the hardware date and time, make sure the OS date and time is set appropriately as shown in the hack#7. Set the hardware date and time based on the system date as shown below: # hwclock –systohc # hwclock --systohc –utc Use hwclock without any parameter, to view the current hardware date and time: <nowiki># </nowiki>hwclock Check the clock file to verify whether the system is set for UTC: <nowiki># </nowiki>cat /etc/sysconfig/clock ZONE="America/Los_Angeles" UTC=false ARC=false =='''Hack 9. Display Current Date and Time in a Specific'''== '''Format''' Following are different ways of displaying the current date and time in various formats: $ date Thu Jan 1 08:19:23 PST 2009 $ date --date="now" Thu Jan 1 08:20:05 PST 2009 $ date --date="today" Thu Jan 1 08:20:12 PST 2009 $ date --date='1970-01-01 00:00:01 UTC +5 hours' +%s 18001 $ date '+Current Date: %m/%d/%y%nCurrent Time:%H:%M:%S' Current Date: 01/01/09 Current Time:08:21:41 $ date +"%d-%m-%Y" 01-01-2009 $ date +"%d/%m/%Y" 01/01/2009 $ date +"%A,%B %d %Y" Thursday,January 01 2009 Following are the different format options you can pass to the date command: {| style="border-spacing:0;" | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| o | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| %D | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| date (mm/dd/yy) |- | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| o | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| %d | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| day of month (01..31) |- | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| o | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| %m | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| month (01..12) |- | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| o | colspan="2" style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| %y last two digits of year (00..99) |- | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| o | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| %a | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| locale’s abbreviated weekday name (Sun..Sat) |} # %A locale’s full weekday name, variable length (Sunday..Saturday) o %b locale’s abbreviated month name (Jan..Dec) # %B locale’s full month name, variable length (January..December) {| style="border-spacing:0;" | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| o | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| %H | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| hour (00..23) |- | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| o | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| %I | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| hour (01..12) |- | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| o | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| %Y | style="border:none;padding-top:0in;padding-bottom:0in;padding-left:0.075in;padding-right:0.075in;"| year (1970…) |} =='''Hack 10. Display Past Date and Time'''== Following are various ways to display a past date and time: $ date --date='3 seconds ago' Thu Jan 1 08:27:00 PST 2009 $ date --date="1 day ago" Wed Dec 31 08:27:13 PST 2008 $ date --date="1 days ago" Wed Dec 31 08:27:18 PST 2008 $ date --date="1 month ago" Mon Dec 1 08:27:23 PST 2008 $ date --date="1 year ago" Tue Jan 1 08:27:28 PST 2008 $ date --date="yesterday" Wed Dec 31 08:27:34 PST 2008 $ date --date="10 months 2 day ago" Thu Feb 28 08:27:41 PST 2008 =='''Hack 11. Display Future Date and Time'''== Following examples shows how to display a future date and time. $ date Thu Jan 1 08:30:07 PST 2009 $ date --date='3 seconds' Thu Jan 1 08:30:12 PST 2009 $ date --date='4 hours' Thu Jan 1 12:30:17 PST 2009 $ date --date='tomorrow' Fri Jan 2 08:30:25 PST 2009 $ date --date="1 day" Fri Jan 2 08:30:31 PST 2009 $ date --date="1 days" Fri Jan 2 08:30:38 PST 2009 $ date --date="2 days" Sat Jan 3 08:30:43 PST 2009 $ date --date='1 month' Sun Feb 1 08:30:48 PST 2009 $ date --date='1 week' Thu Jan 8 08:30:53 PST 2009 $ date --date="2 months" Sun Mar 1 08:30:58 PST 2009 $ date --date="2 years" Sat Jan 1 08:31:03 PST 2011 $ date --date="next day" Fri Jan 2 08:31:10 PST 2009 $ date --date="-1 days ago" Fri Jan 2 08:31:15 PST 2009 $ date --date="this Wednesday" Wed Jan 7 00:00:00 PST 2009
Summary:
Please note that all contributions to TetraWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
TetraWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)