将unitx时间戳转换为可读日期时间的命令行实用程序
ut2d的Python项目详细描述
ut2d
ut2d(unix timestamp to datetime)是一个很小的命令行实用程序,用于将unix timestamp转换为人类可读的datetime。这个工具打算在datetime主题上使用最少的相关包或复杂的计算和转换,并提供一个非常简单的接口来帮助您以超快速的方式转换unix时间戳。
下面是支持的所有功能的列表(详细信息请参见示例部分):
- 获取给定ut的日期时间;
- 获取现在的日期时间;
- 获取日期时间并从现在开始计算时差;
- 获取DateTime并在特定时区中查找给定时间;
- 获取日期时间并在特定城市(任何城市)中找到给定时间(使用刮刀);
如果您经常使用unix时间戳,或者需要一个小实用程序来获取linuxdate
命令无法提供的另一个城市的时间,ut2d
可能会让您的生活更轻松一些。
安装
先决条件:python 3.6或以上
$ pip install ut2d
示例
获取给定ut
的日期时间$ ut2d 1547671090Unix Timestamp: 1547671090.0Local: Wed, Jan 16, 2019 03:38PMGMT : Wed, Jan 16, 2019 08:38PM
获取现在的日期时间
$ ut2d now Unix Timestamp: 1547671189.5133939Local: Wed, Jan 16, 2019 03:39PMGMT : Wed, Jan 16, 2019 08:39PM
从现在开始获取日期时间并计算时间差
$ ut2d 1547671090 -d Unix Timestamp: 1547671090.0Local: Wed, Jan 16, 2019 03:38PMGMT : Wed, Jan 16, 2019 08:38PMGiven time is 11 mins, 5 secs ago
获取datetime并在特定时区中查找给定时间
提供前缀为“GMT”或“UTC”的时区。
$ ut2d now -tz "GMT+8"Unix Timestamp: 1550257565.5289779Local: Fri, Feb 15, 2019 02:06PMGMT : Fri, Feb 15, 2019 07:06PM? The given time in GMT+8 is: Sat, Feb 16, 2019 03:06AM.
获取日期时间并在特定城市中查找给定时间
这是通过从搜索引擎中删除城市的时区来完成的,并计算给定城市的给定unix时间戳的日期时间。
如果搜索“纽约”…(我在波士顿)
$ ut2d 1547671090 -d -c "New York"Unix Timestamp: 1547671090.0Local: Wed, Jan 16, 2019 03:38PMGMT : Wed, Jan 16, 2019 08:38PMGiven time is 15 mins, 42 secs ago? I am finding your city on popular search engines! Plz wait a sec...? I suppose the given time in New York is: Wed, Jan 16, 2019 03:38PM. I have 88% confidence with this result from search engines!
您可以使用now
和-c
标志来获取任何城市的本地时间,甚至可以使用其他语言。例如北京和法国的蒙特勒朱格内。
$ ut2d now -c "北京"Unix Timestamp: 1547673691.203567Local: Wed, Jan 16, 2019 04:21PMGMT : Wed, Jan 16, 2019 09:21PM? I am finding your city on popular search engines! Plz wait a sec...? I suppose the given time in 北京 is: Thu, Jan 17, 2019 05:21AM. I have 88% confidence with this result from search engines!$ ut2d now -c "Montreuil-Juigné"Unix Timestamp: 1547673563.7226071Local: Wed, Jan 16, 2019 04:19PMGMT : Wed, Jan 16, 2019 09:19PM? I am finding your city on popular search engines! Plz wait a sec...? I suppose the given time in Montreuil-Juigné is: Wed, Jan 16, 2019 10:19PM. I have 88% confidence with this result from search engines!
你可以在这里搜索任何东西!但如果在搜索引擎上找不到,它就不会打印出时间。
许可证
这个软件是在MIT license下发布的。