【问题标题】:Equivalent of moment react in java等效于Java中的时刻反应
【发布时间】:2021-01-22 16:47:23
【问题描述】:

我必须找出开始和完整加载时间事件之间的区别。开始加载在 java 中,而结束在 react 中。

在反应中我有这个

completeLoad = moment();

我想在java中记录下初始加载时间,然后找出两者的区别。我不确定如何以与 momemt() 类似的格式在 java 中记录时间。在这里需要一些帮助。

【问题讨论】:

  • 您可以使用System.currentTimeMillis() 将时间戳(以毫秒为单位)插入到变量中(如果您使用某些模板引擎生成 HTML),然后从其中创建一个新的 Date JS.

标签: java reactjs momentjs epoch instant


【解决方案1】:

在 Java 中,Instant 对时间线上的单个瞬时点进行建模。 Instant#now 为您提供系统时钟的当前时刻。

import java.time.Instant;

public class Main {
    public static void main(String[] args) {
        Instant now = Instant.now();
        System.out.println(now);
        System.out.println(now.toEpochMilli());
        System.out.println(now.getEpochSecond());
    }
}

样本运行的输出:

2020-10-07T17:16:10.487996Z
1602090970487
1602090970

【讨论】:

    猜你喜欢
    • 2016-03-28
    • 2019-11-02
    • 2016-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多