如何在终端中获取当前日期和时间并在终端中为其设置自定义命令? [关闭]

本文翻译自:How to get the current date and time in the terminal and set a custom command in terminal for it? [closed]

I have to check the time in linux terminal. 我要检查linux终端的时间。
What is the command for getting date and time in Linux terminal ? 在Linux终端中获取日期和时间的命令是什么?
Is there any way in which we can set custom function ? 有什么方法可以设置自定义功能吗?


#1楼

参考:https://stackoom.com/question/1FRzD/如何在终端中获取当前日期和时间并在终端中为其设置自定义命令-关闭


#2楼

You can use date to get time and date of a day: 您可以使用date来获取一天的时间和日期:

[pengyu@GLaDOS ~]$date
Tue Aug 27 15:01:27 CST 2013

Also hwclock would do: hwclock也会:

[pengyu@GLaDOS ~]$hwclock
Tue 27 Aug 2013 03:01:29 PM CST  -0.516080 seconds

For customized output, you can either redirect the output of date to something like awk , or write your own program to do that. 对于自定义输出,您可以将date输出重定向到类似awk ,或者编写自己的程序来执行此操作。

Remember to put your own executable scripts/binary into your PATH (eg /usr/bin) to make it invokable anywhere. 记得将自己的可执行脚本/二进制文件放入PATH (例如/ usr / bin),以使其可以在任何地方调用。

However, I don't think this is a good question for StackOverflow. 但是,我认为这对StackOverflow来说不是一个好问题。


#3楼

The command is date 命令是date

To customise the output there are a myriad of options available, see date --help for a list. 要自定义输出,可以使用多种选项,请参阅date --help帮助列表。

For example, date '+%A %W %Y %X' gives Tuesday 34 2013 08:04:22 which is the name of the day of the week, the week number, the year and the time. 例如, date '+%A %W %Y %X'给出Tuesday 34 2013 08:04:22这是星期几的名称,星期数,年份和时间。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值