繁体   English   中英

如何正确使用Joda-Time Instant方法

[英]How to properly use Joda-Time Instant method

在计算两个小时之间差异的应用程序中,我使用了Joda-Time Instant类,但是出了点问题,或者我真的不知道如何使用它。 我的代码如下:

Instant start = Instant.now(); //to set current system time
textView.setText(start); //to display current time in textView

可悲的是,有一个错误说:

无法解析方法'setText(org.joda.time.Instant)

如何正确显示当前时间?

textView.setText接受String参数。 您应该将Instant作为String传递:

Instant start = Instant.now();
textView.setText(start.toString());

假设您使用首选的输出格式设置了DateTimeFormatter ,则可能需要这样做:

textView.setText(DATE_TIME_FORMATTER.print(start));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM