Emacs Lisp 的 strtotime

发布于 2024-08-05 05:42:32 字数 466 浏览 4 评论 0原文

Emacs Lisp 中是否有任何功能与 PHP 的 strtotime 函数 类似? (实际上据我所知,它实现了 relative GNU 日期输入格式的项目。)

在 PHP 中,我可以编写

echo strtotime("+2 months"); //1258891352
echo strtotime("-3 months +2 weeks"); //1246952239

返回相应 UNIX 时间戳的代码。

Is there any functionality in Emacs Lisp that behaves similar to PHP's strtotime function? (Actually AFAIK it implements relative items of the GNU date input formats.)

In PHP I can write

echo strtotime("+2 months"); //1258891352
echo strtotime("-3 months +2 weeks"); //1246952239

which return the corresponding UNIX timestamps.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

假装不在乎 2024-08-12 05:42:32

虽然不完全是您所要求的,但这可能有用。 org-mode 包中有一个命令 'org-schedule ,它有一个非常好的选择日期的界面。执行此操作的具体命令是 'org-read-date ,它理解表示日期的多种方式,包括:

 +0            --> today
 .             --> today
 +4d           --> four days from today
 +4            --> same as above
 +2w           --> two weeks from today
 ++5           --> five days from default date
 +2tue         --> second Tuesday from now.

如果您正在寻找一种交互式方式来使用方便的语法糖来指定日期,那么该例程应该非常适合您的要求。如果您正在寻找编程解决方案,上面的命令看起来就像调用 'org-read-date-analyze 来完成这项工作。注意:它的用法有点晦涩(它的两个参数从未定义过......),所以如果您无法直接弄清楚它,可能值得将邮件发送到 组织邮件列表

While not exactly what you're asking for, this may be of use. There's a command 'org-schedule in the package org-mode that has a really nice interface to choosing dates. The specific command that does it is 'org-read-date, which understands many ways of representing the date, including:

 +0            --> today
 .             --> today
 +4d           --> four days from today
 +4            --> same as above
 +2w           --> two weeks from today
 ++5           --> five days from default date
 +2tue         --> second Tuesday from now.

If you're looking for an interactive way to specify dates with that handy syntactic sugar, that routine should fit the bill nicely. If you're looking for a programmatic solution, it looks as though the above command calls 'org-read-date-analyze to do the leg work. Note: its usage is a little obscure (two of its arguments are never defined...), so if you can't figure it out directly, it might be worth sending mail to the org mailing list.

知你几分 2024-08-12 05:42:32
(defun string-to-time (date)
  (shell-command-to-string (format "date --date='%s' +%%s" date)))
(defun string-to-time (date)
  (shell-command-to-string (format "date --date='%s' +%%s" date)))
流年里的时光 2024-08-12 05:42:32

我所知道的最接近的内置函数是编码时间。如果你想使用自然语言,你可能不得不写这样的东西: http://github .com/chaitanyagupta/chronicity

The closest inbuilt function I know of is encode-time. If you want to use natural language, you'll probably have to end up writing something like this: http://github.com/chaitanyagupta/chronicity

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文