如何在Java 9中使用JShell获取日期和时间?

2023年 8月 28日 77.0k 0

如何在Java 9中使用JShell获取日期和时间?

If we want to get the current date with time in JShell by using the below code snippet.

C:UsersUser>jshell
| Welcome to JShell -- Version 9.0.4
| For an introduction type: /help intro

jshell> new Date()
$1 ==> Fri Feb 28 11:59:23 IST 2020

jshell>

登录后复制

在下面的代码片段中,我们需要获取一个日期和毫秒数。

jshell> new Date().getTime()
$2 ==> 1582871487654

jshell> System.currentTimeMillis()
$3 ==> 1582871513421

jshell> new Date(1582871513421L)
$4 ==> Fri Feb 28 12:01:53 IST 2020

jshell>

登录后复制

In the below code snippet, we need to get the time.

jshell> java.time.Instant.now()
$5 ==> 2020-02-28T07:07:33.941720100Z

jshell>

登录后复制

以上就是如何在Java 9中使用JShell获取日期和时间?的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!

相关文章

JavaScript2024新功能:Object.groupBy、正则表达式v标志
PHP trim 函数对多字节字符的使用和限制
新函数 json_validate() 、randomizer 类扩展…20 个PHP 8.3 新特性全面解析
使用HTMX为WordPress增效:如何在不使用复杂框架的情况下增强平台功能
为React 19做准备:WordPress 6.6用户指南
如何删除WordPress中的所有评论

发布评论