- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
public Timestamp Timestamp() {
int hours = new Timestamp(System.currentTimeMillis()).getHours();
int minutes = new Timestamp(System.currentTimeMillis()).getMinutes();
int seconds = new Timestamp(System.currentTimeMillis()).getSeconds();
String activity = "\n" + minutes + ":" + hours + ":" + seconds;
return null;
}
getHours
、getMinutes
和 getSeconds
方法被删除并且不起作用?
我正在尝试将时间戳存储到 txt 文件中,并在其他地方调用它来创建 Activity 日志。
最佳答案
当您使用System.currentTimeMillis()
时,我假设这是Java。 “删除”,您的意思是您的 IDE 中的方法名称有删除线吗?
如果是这种情况,则意味着这些方法已被弃用。实际上,Timestamp
inherits those methods from Date
,这些是 deprecated since Java 1.1 .
如果您希望将当天的当前时间格式化为String
,我建议您使用new date/time API 。在 Java 8 及更高版本中,这些是 native 的,位于 java.time 包中。对于较低版本,您可以使用Threeten Backport ,并且相同的类将在 org. Threeten.bp
包中提供:
// current time
LocalTime now = LocalTime.now();
// formatter (hours:minutes:seconds)
DateTimeFormatter fmt = DateTimeFormatter.ofPattern("HH:mm:ss");
// format the LocalTime to String
String activity = now.format(fmt);
我使用了一种格式HH:mm:ss
,这意味着“小时:分钟:秒”(与您使用的顺序不同:“分钟:小时:秒”),并且还包含 2数字(因此“9”变为“09”)。如果这不是您需要的确切格式,check in the javadoc如何获得不同的格式。
关于java - getMinutes、getHour 和 getSeconds 被删除了吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49309414/
Date() 如何处理翻转? 假设您调用 getMinute() 并返回 10。您调用 getSecond() 并返回 0。那是因为时间是第 10 分钟的第 0 秒,还是因为在两次通话之间时钟翻到了新
本文整理了Java中java.time.ZonedDateTime.getSecond()方法的一些代码示例,展示了ZonedDateTime.getSecond()的具体用法。这些代码示例主要来源于
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
我使用以下方法来计算耗时: var start = new Date(); var end; var total; end = new Date(); tota
据我所知,getHours()、getMinutes() 和 getSeconds() 在 Java 中都已弃用,它们被替换为 Calendar.HOUR_OF_DAY、Calendar.MINUTE
public Timestamp Timestamp() { int hours = new Timestamp(System.currentTimeMillis()).getHours();
寻找一种创造性的方法来确保来自 javascript Date 对象的 getHours、getMinutes 和 getSeconds() 方法的值返回 "06" 而不是 6(例如)。有什么我不知道
我想在获取 Date.getHours()、Date.getMinutes() 和 Date.getSeconds() 的值后格式化输出>. 这是一条漫长的路: var dt = new Date()
本文整理了Java中com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl.getSecond()方法的一些
本文整理了Java中com.sun.org.apache.xerces.internal.jaxp.datatype.XMLGregorianCalendarImpl.getSeconds()方法的一
我们正在为我们的月球研究使用 28 小时的时钟系统, 这是我们尝试在 Canvas HTML 中创建它的方式,* 1 分钟 = 56 秒* 1 小时 = 56 分钟在此基础上,我们试图创建一个运行 1
我是一名优秀的程序员,十分优秀!