英文:
Equivalent of moment react in java
问题
我必须找到开始加载时间和完成加载时间事件之间的差异。开始加载时间在Java中,而结束时间在React中。
在React中,我有这样的代码:
completeLoad = moment();
我想要记录Java中的初始加载时间,然后找到两者之间的差异。我不确定如何在Java中以类似 moment()
的格式记录时间。在这方面需要一些帮助。
英文:
I have to find the difference between the start and the complete load time event. The start load is in java whereas end is in react.
In react I have this
completeLoad = moment();
I want to record the initial load time in java and then find the difference between the two. I am not sure how to record time in java in similar format as momemt(). Need some help here.
答案1
得分: 3
在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
英文:
In Java, you have Instant which models a single instantaneous point on the time-line. Instant#now
gives you the current instant from the system clock.
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());
}
}
Output from a sample run:
2020-10-07T17:16:10.487996Z
1602090970487
1602090970
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论