本文介绍了从Java日期添加/减去5秒-显示不正确的警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在当前时间增加5秒

I want to add 5 seconds to current time

    Date date = new Date();

    date.setSeconds(date.getSeconds()+ 5);
    System.out.println("old Value is: "+date);
    System.out.println("New Value is: "+ date);

它完全按照我的需要生成正确的输出:

It generates the correct output exactly what I needed as:

Old Value is: Thu Apr 17 14:10:33 PKT 2014
New Value is: Thu Apr 17 14:10:38 PKT 2014

但是它给我一个警告错误消息,如

but it gives me a warning error message as

Multiple markers at this line
    - The method getSeconds() from the type Date is deprecated
    - The method setSeconds(int) from the type Date is 
     deprecated

这是什么意思.忽略此警告是否安全?如果没有,该如何处理?

What this means. Is it safe to ignore this warning? if not then how to handle it?

推荐答案

您可以使用 date.setTime(date.getTime()+ 5000)

这篇关于从Java日期添加/减去5秒-显示不正确的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 05:46