Date

From Unix SME

Command name:

 date 

Description :

The 'date' command in Linux is used to display the current date and time or to set the system's date and time. There are more options available for formatting and adjusting the date and time based on your needs. You can check the 'man' pages for 'date' to explore more options and functionalities.

Syntax:

 date [OPTION]... [+FORMAT]
date [-u/--utc/-universal] [MMDDhhmm[[CC]YY][.ss]]


Use case:

 The date command in Linux is versatile and finds application in various scenarios that require the user to show the systems time or change it.

Examples:

 1. date - Display the current date and time
    Example -- Mon Feb  5 07:17:24 PM MST 2024
 2. date +"%Y-%m-%d %H:%M:%S" - Display the date and time in a specific format
    Example -- 19:17 [date +%R]
 
 3. date +"%A" - Display the day of the week
 4. date +"%B" - Display the month
 5. date -u - Display the current time in UTC
 6. date --date="yesterday" - Display the date and time of yesterday
 7. date --date="tomorrow" - Display the date and time of tomorrow
 8. sudo date MMDDhhmm[[CC]YY][.ss] - Set the system date and time (requires sudo)
 9. TZ="America/New_York" date - Display the date and time of a specific timezone, such as New York
 10.TZ="Asia/Tokyo" date +"%Y-%m-%d %H:%M:%S" - Display the date and time of a specific timezone in a custom format
 11. date -s "next year" - Sets the system date to one year from now.
 12. date -s "2024-08-20 11:15:10" - Sets the system date to a specific time. In example, sets the time to October 20th 2024 at 11:15 AM.