4

我想在 GNU Octave 中获取日期和时间并将其打印到屏幕上。做这个的最好方式是什么?

我检查了 Octave 文档,但没有看到使用单行简单命令打印出 YYYY-MM-DD HH:MM:SS 的功能。我可以做到,只需要 2 或 3 行来组装它。如何将八度音阶中的 yyyy-mm-dd hh:mm:ss 作为字符串?

http://www.gnu.org/software/octave/doc/interpreter/Timing-Utilities.html

4

1 回答 1

6

回顾所有在 Octave 中获得时间的方法:

1.时间命令:

time ()

ans = 1.3482e+09

一个数字,它是当前时间,表示自纪元以来的秒数。纪元参考 1970 年 1 月 1 日 00:00:00 CUT(协调世界时)。

2.时钟命令:

clock

它以矩阵格式返回日期 2012-09-20 21:46:12:

2012.0000      9.0000     20.0000     21.0000     46.0000     12.2778

3.日期命令:

date ()

ans = 20-Sep-2012

4. strftime(fmt, tm_struct) 命令

strftime ("%r (%Z) %A %e %B %Y", localtime (time ()))

ans = 09:52:42 PM (EDT) Thursday 20 September 2012

5.使用strftime获取yyyy-mm-dd hh:mm:ss格式

strftime ("%Y-%m-%d %H:%M:%S", localtime (time ()))

ans = 2012-09-20 21:56:07

有关 strftime 格式修饰符 ( %r, %Z...) 的描述,请参见:

https://octave.sourceforge.io/octave/function/strftime.html

于 2012-09-20T13:58:57.463 回答