当前位置:网站首页>8 examples of using date commands
8 examples of using date commands
2022-07-02 12:40:00 【Teacher Liu Trent】
date command Used to display and set Linux System Date and time settings on . This tutorial provides an overview of how to use date command stay Linux Display and set the date on the system . |
Without options Date command
date Command without any command options , It displays the current date and time , Including the day of the week , month , year ,h:m:s Time and time zone in format , As shown below .
[[email protected] ~]# date
Mon May 24 14:50:31 CST 2021
- 1.
- 2.

Display in world standard time
To use UTC( World standard time ) Display time , Need to add -u Options .
[[email protected] ~]# date -u
Mon May 24 06:51:21 UTC 2021
- 1.
- 2.

Displays a specific date in string format
have access to --date Option to display a specific date in string format , This does not affect the date and time of the system , Just convert the date format to a string :
[[email protected] ~]# date --date="5/20/2021 13:14"
Thu May 20 13:14:00 CST 2021
- 1.
- 2.

Use date Command to check past dates
date The command can also print past dates and times relative to the current date . For example, view 9 What was the date the day before , Please run the command :
[[email protected] ~]# date --date="9 days ago"
Sat May 15 14:56:47 CST 2021
- 1.
- 2.

Look at the date three months ago :
[[email protected] ~]# date --date="3 months ago"
Wed Feb 24 14:57:29 CST 2021
- 1.
- 2.

Look at the date today two years ago :
[[email protected] ~]# date --date="2 years ago"
Fri May 24 15:02:40 CST 2019
- 1.
- 2.

Use date Command to check future dates
date The command can also display future dates , For example, look at tomorrow's date :
[[email protected] ~]# date --date="tomorrow"
Tue May 25 14:58:49 CST 2021
- 1.
- 2.

Check the exact date a week from now , Please run :
[[email protected] ~]# date --date="next week"
Mon May 31 14:59:27 CST 2021
- 1.
- 2.

Show 3 Date after week :
[[email protected] ~]# date --date="3 weeks"
Mon Jun 14 15:00:11 CST 2021
- 1.
- 2.

Show 4 Months later , Do the following :
[[email protected] ~]# date --date="4 months"
Fri Sep 24 15:01:42 CST 2021
- 1.
- 2.

Show today's date two years later :
[[email protected] ~]# date --date="2 years"
Wed May 24 15:03:32 CST 2023
- 1.
- 2.

date Command options
date The command comes with many options , Face lists some of the available formatting options .
- %D – The date display format is month / Japan / year
- %Y – year ( for example :2021)
- %m – month (01-12)
- %B – The full name of the month ( for example January)
- %b – Short name of the month ( for example Jan)
- %d – Which day of the month ( for example 01)
- %j – The day of the year (001-366)
- %u – Day of the week (1-7)
- %A – What day of the week ( for example Friday)
- %a – Short name of the day of the week ( for example Fri)
- %H – Hours ,24 hourly (00-23)
- %I – Hours ,12 hourly (01-12)
- %M – minute (00-59)
- %S – second (00-60)
Use date The syntax of options is very simple :
date "+%option"
- 1.
for example , To use yy/mm/dd Format print date , Please run :
[[email protected] ~]# date "+%Y/%m/%d"
2021/05/24
- 1.
- 2.

What day of the week do you want to print , month , Japan , Year and current time , Do the following :
[[email protected] ~]# date "+%A %B %d %Y %T"
Monday May 24 2021 15:24:07
- 1.
- 2.
How to set the date and time
date The command also allows you to set the date and time . for example , To set the date and time to 2021 year 6 month 25 The morning of 11:15, Please run the following command :
[[email protected] ~]# date --set="20210625 11:15"
Fri Jun 25 11:15:00 CST 2021
- 1.
- 2.
Use in variables date command
Creating Shell Script When , We will date Save the command to a variable , Then use this variable to create a log file , An example is shown below :
#!/bin/bash
LOGFILE=/tmp/logs-$(date +%d-%m-%Y_%T)
echo "##Check Cluster for Failed Resources##" >> $LOGFILE
crm_mon -1 -rf | grep FAILED >> $LOGFILE
echo -e "\n\n" >> $LOGFILE
echo "##Check Cluster for Stopped Resources##" >> $LOGFILE
crm_mon -1 -rf | grep -i STOPPED >> $LOGFILE
echo -e "\n\n" >> $LOGFILE
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
summary
date Commands are used to display and set Linux Date and time settings on the system . This tutorial provides an overview of how to use date Command in Linux Display and set the date on the system .
边栏推荐
- This "little routine" is set on the dough cake of instant noodles. No wonder programmers are always hungry
- drools中then部分的写法
- 通过反射执行任意类的任意方法
- Docker-compose配置Mysql,Redis,MongoDB
- Mysql database foundation
- 哈希表 AcWing 840. 模拟散列表
- CDH6之Sqoop添加数据库驱动
- When uploading a file, the server reports an error: iofileuploadexception: processing of multipart / form data request failed There is no space on the device
- Openssh remote enumeration username vulnerability (cve-2018-15473)
- Embedded Software Engineer career planning
猜你喜欢

Find the common ancestor of any two numbers in a binary tree

通过反射执行任意类的任意方法

spfa AcWing 851. spfa求最短路

bellman-ford AcWing 853. 有边数限制的最短路

Anxiety of a 211 programmer: working for 3 years with a monthly salary of less than 30000, worried about being replaced by fresh students

spfa AcWing 852. spfa判断负环

分布式机器学习框架与高维实时推荐系统

async/await 异步函数

"As a junior college student, I found out how difficult it is to counter attack after graduation."

AAAI 2022 | Peking University & Ali Dharma Institute: pruning and compression of pre training language model based on comparative learning
随机推荐
线性DP AcWing 897. 最长公共子序列
[ybtoj advanced training guidance] judgment overflow [error]
CDA data analysis -- Introduction and use of aarrr growth model
Redis transaction mechanism implementation process and principle, and use transaction mechanism to prevent inventory oversold
线性DP AcWing 899. 编辑距离
LeetCode—<动态规划专项>剑指 Offer 19、49、60
Distributed machine learning framework and high-dimensional real-time recommendation system
哈希表 AcWing 841. 字符串哈希
drools执行指定的规则
Redis introduction, scenario and data type
JS10day(api 阶段性完结,正则表达式简介,自定义属性,过滤敏感词案例,注册模块验证案例)
kubenetes中port、targetPort、nodePort、containerPort的区别与联系
Go学习笔记—多线程
async/await 异步函数
上传文件时,服务器报错:IOFileUploadException: Processing of multipart/form-data request failed. 设备上没有空间
软件测试面试题-2022年大厂面试题合集
通过反射执行任意类的任意方法
PR 2021 quick start tutorial, learn about the and functions of the timeline panel
Anxiety of a 211 programmer: working for 3 years with a monthly salary of less than 30000, worried about being replaced by fresh students
Leetcode - Sword finger offer 59 - I, 59 - II