date MacOS command
The date
command in MacOS allows users to display and set the system date and time. It offers various options to customize the date and time format, calculate time differences, and perform other date-related tasks. By using this versatile command, MacOS users can efficiently manage date and time operations directly from the terminal.
date Syntax:
Options:
Option | Description |
---|---|
-d, —date | Display the date specified |
-u, —utc | Print or set Coordinated Universal Time (UTC) |
-r, —reference | Display the last modification time of a file |
-R, —rfc-2822 | Output date and time in RFC 2822 format |
-I, —iso-8601 | Output date and time in ISO 8601 format |
-j, —date=%s | Display time as seconds since epoch (1970) |
-f, —file | Use date from a file instead of current date |
Parameters:
Parameter | Description |
---|---|
+FORMAT | Use FORMAT as the output date and time format |
date bash Examples:
Display the current date and time
Display the current date and time in the default format.
Display the date in a specific format
Display the date and time in a customized format.
Display the day of the week
Display the full name of the day of the week.
Display the time in 12-hour format
Display the time in 12-hour format with AM/PM.
Display the week number of the year
Display the week number of the year (starting on Sunday).
Convert a date string to a Unix timestamp
Convert a specific date and time string to a Unix timestamp.
How do I format the output of the date command in MacOS?
To format the output of the date command in MacOS, use the following command:
How can I display the current date and time using the date command in MacOS?
To display the current date and time using the date command in MacOS, run the following command:
How do I display the current date in a specific timezone with the date command in MacOS?
To display the current date in a specific timezone using the date command in MacOS, use the following command:
How can I get the epoch/Unix timestamp using the date command in MacOS?
To get the epoch/Unix timestamp using the date command in MacOS, execute the following command:
How do I show the calendar for a specific year with the date command in MacOS?
To show the calendar for a specific year using the date command in MacOS, run the following command:
How can I display the week number of the current year with the date command in MacOS?
To display the week number of the current year using the date command in MacOS, use the following command:
How do I find the day of the week for a specific date with the date command in MacOS?
To find the day of the week for a specific date using the date command in MacOS, run the following command:
Applications of the date command
- Displaying the current date and time
- Converting timestamps to human-readable dates
- Setting the system date and time
- Calculating time differences
- Formatting date and time in scripts