Date (Unix command): Difference between revisions

Content deleted Content added
GelvinM (talk | contribs)
Added to description that the system date can be set using the command with a reference.
GelvinM (talk | contribs)
Added note on related environment variables that can change the output of the command. Fixed ISBN of Linux for Programmers book.
Line 3:
==Option flags==
 
*+”''date format codes”'' Alters the output using the specified date conversion codes which are prefaced with at % sign. <ref name=KerriskLocale>{{cite web |last=Kerrisk |first=Michael |date=Feb 2, 2025 |title=date(1) — Linux manual page |url=https://man7.org/linux/man-pages/man1/date.1.html |access-date=Mar 20, 2025 |website=man7.org |publisher=}}</ref> date +”Today is day %j of the year %Y and it’s a %A”
 
Output: Today is day 078 of the year 2025 and it’s a Wednesday
Line 21:
*-r or --reference=''filename ''- outputs the last modification time of the file
 
*-s or --set=”''datestring”'' sets the current date and time to the value of ''datestring.'' Requires an account with admin privilege.<ref>{{cite book |last1=Glass |firstfirst1=Graham | last2=King| first2=Ables\|date=2006 |title=Linux for Programmers and Users ||___location=Upper Saddle River, NJ |publisher=Pearson Prentice Hall |page=44|isbn=978-0131757483 |access0131-date=857483}} </ref>
 
*-u or --UTC displays [[Universal time|Greenwich Mean Time]]
 
==Related Environment Variables==
 
*LC_TIME - changes the language and default order and format in which the date is presented
 
export LC_TIME=fr_CA.utf8
 
The value corresponds assigned to LC_TIME refers to files found in /usr/share/i18/locale. The file name is usually of the form languageCode_countryCode where the codes are the two character ISO codes for [[language|List of ISO 639 language codes]] or [[country|List of ISO 3166 country codes6]] <ref>{{cite web| author=<!-- not stated --> |title=Locale Environment Variables: Locale Names |url=https://www.gnu.org/software/gettext/manual/html_node/Locale-Names.html|website=www.gnu.org |publisher=gnu.org |access-date=Mar 20, 2025}}</ref>
 
It is also possible to change the date presentation format by setting the environment variables LANG or LC_ALL however these will also change other presentation formats such as LC_MESSAGE (command error messages) and LC_MONETARY which many not be desirable.<ref name=KerriskLocale></ref>
 
 
 
*TZ - Alters the output of the command to reflect the designated time zone.
 
export TZ=Africa/Nairobi
 
The directory /usr/share/zoneinfo contains a large group of [[tz database| timezone database files|]] files describing both current and historical definitions of local times to facilitate the correct reproduction and translation of time information from one time zone and era to another. The files keep track of the offset from Greenwich Mean Time as well as when seasonal adjustments have been scheduled to take place such as the transition to and from [[Daylight saving time|Daylight Saving Time]] (DST). <ref>{{cite book |last=Ward |first=Brian |date=April 19, 2021 |title=How Linux Works, 3rd Edition |publisher=No Starch Press |section=7.5.1 |isbn=978-1718-500402}} </ref>
 
==References==
{{reflist}}