Linux Date Command: Get Current Year, Month, Day

In Linux systems, you can use the date command to retrieve and display the current date.

To retrieve the current date in year, month, and day, you can use the following command in the terminal:

date +"%Y-%m-%d"

This command will display the current date in the format YYYY-MM-DD. You can also customize the output format as needed, for example:

date +"%Y年%m月%d日"

This will output a format similar to “January 01, 2023”.

Additionally, you can assign the current date and time to a variable, and then perform other operations on it.

current_date=$(date +"%Y-%m-%d")
echo "当前日期是:$current_date"

In this way, you can save the current date in the variable current_date and display it on the screen.

bannerAds